Another Way to Create a GitHub Repository
Saturday, February 4, 2017
By: Matthew Doucette

I was having troubles pushing a local project to a new GitHub repository. I could set up a repo on GitHub no problem, however I could not sync it with a local repo. Check out the following two methods:

 

Ideal Method (Which Failed for Me):

Here is what failed for me:

  1. Create repo on GitHub, then come back to local Git Shell:
  2. git init
  3. git add *.*
  4. git commit -m "Initial commit"
  5. git remote add origin https://github.com/<user>/repo
  6. git push origin master

The "git push" would fail with the following error:

~<path> [master +1076 ~0 -0 !]> git push origin master
To https://github.com/<user>/repo
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/<user>/repo'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

I would try to do a "git pull" to fix it, but it would fail with an error I did not record. Contact me if you run into this same issue.

 

Alternative Method:

Here is an alternate method, proposed by friend Wayne Muise of MudMonger Games:

  1. Move your local project to another folder, and create an emtpy folder where you want your project to go.
  2. Create repo on GitHub, then come back to local Git Shell:
  3. git clone https://github.com/<user>/repo .
  4. Copy local project into this (now not emtpy) folder where you want your project to go.
  5. git add *.*
  6. git commit -m "Initial commit"
  7. git push origin master

Notes:

  1. The idea here is to move your project into the folder after you download the GitHub repo into the empty folder.
  2. Add a readme file and a .gitignore file if you wish.
  3. This downloads the "origin" branch on GitHub to your local "master" branch on your computer, into your empty folder. You should see your readme file and .gitignore locally if you have chosen to create them. You will also get a .git folder. Note the dot, ".". Without the dot, it creates a folder. With the dot, it downloads to the current folder. If you make a mistake, you can delete the local mistake (delete the files via Windows Explorer) and do it again.
  4. Git will think you just made all these project files and treat them as new.
  5. No comment.
  6. No comment.
  7. You could also use "git push -u origin master" and, with using "-u", never have to specific "origin master" again.

Works! Done!

That is all!

 

 

About the Author: I am Matthew Doucette of Xona Games, an award-winning indie game studio that I founded with my twin brother. We make intensified arcade-style retro games. Our business, our games, our technology, and we as competitive gamers have won prestigious awards and received worldwide press. Our business has won $180,000 in contests. Our games have ranked from #1 in Canada to #1 in Japan, have become #1 best sellers in multiple countries, have won game contests, and have held 3 of the top 5 rated spots in Japan of all Xbox LIVE indie games. Our game engines have been awarded for technical excellence. And we, the developers, have placed #1 in competitive gaming competitions -- relating to the games we make. Read about our story, our awards, our games, and view our blog.



Home | Games | Awards | About | Learn | Blog | Press Kit | Contact
Email:

Xona Games, Xona.com, Xonatech, Saw Tooth Distortion, Evolutionary Prototype (EP), Duality ZF, Decimation X, Decimation X2,
Decimation X3, Decimation X3.5, Decimation X4, Score Rush, Score Rush 2, Score Rush (HTML5), Score Rush MP, and Score Rush Extended (Score Rush EX)
trademarked and copyrighted by Xona Games Inc., Matthew Doucette, and/or Jason Doucette.
© 2000..2005 Saw Tooth Distortion. © Xona.com. © 2008..2010 Xona Games (under Xona.com).
© Xona Games Inc.

We make Intense Retro video games.