Posted November 23, 2012 in Git

Git Rejected Error On New Repo

Problem: Git returns, ! [rejected] master -> master on a brand new repo.
I’ve been using Git since May of this year. At first I didn’t have any problems performing the basic functions. A friend and I were developing a mobile app with a Rails backend and we had a decent workflow going. Even as a total newbie I was able to add changes to the staging area, commit, push and pull to get the latest revisions. Everything was great, until I got busy with other projects and stopped working on our app for about two months.

I returned to GitHub after their big overhaul of the UI. I wanted to create a test repo to dust off my skills before diving back into our private repo and screwing things up. I followed the steps here, which led to the error in question. What could possibly be going wrong? I was doing everything according to the letter: creating a repo on GitHub, initializing a local repo, adding changes, committing and pushing all according to the documentation. Yet, every time, I got the same error:

It was boggling, to say the least. How could there be an error on a freshly-created repo? Confused, I ran git --version to see if maybe I was using an old version. I wasn’t on 1.8, but, my version also didn’t seem so old that it would account for the error. After reading countless tutorials and StackOverflow entries, I went to bed angry!

When I awoke the next morning, the thought hit me: “this must be related to the README creation!” Before their UI overhaul, there was no checkbox to automatically insert a README file, so I never did. Then I remembered that the day before, I checked this box every time I created a new repo. In retrospect, my local repo never contained the README file that was created by checking that box. That explained why Git would be acting like the two repos are out of sync: they were! When I was trying to push, the GitHub repo contained a README file that my local repo didn’t. “That must be it,” I thought, immediately opening up Terminal to test the assumption. Sure enough, I created a new repo on GitHub leaving the README box unchecked, and everything worked just fine.

So, if you’re experiencing the same problem on a brand new repo, try it with the README box unchecked. It worked for me. For seasoned Git users this may have been obvious, but for newcomers, I can see how it would cause headache. I love GitHub, I really do, but at the same time, you’d think they would take things like this into consideration when redesigning their UI. All they’d have to do is include a line by the README checkbox which says something like, “Be aware that if you check this box, you’ll need to clone or pull your project to your local repo before you can push without error.” That simple line would have saved me a ton of a headache!

Got Something To Say:

Your email address will not be published. Required fields are marked *