Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialIan de Jesus
8,559 PointsError when pushing to origin
I get this error when I tried to push to origin. I have done the necessary commands to pull and merge conflicts with the master repo but I still get this error.
$ git push origin git_2b
Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 489 bytes | 0 bytes/s, done.
Total 4 (delta 2), reused 0 (delta 0)
remote: error: refusing to update checked out branch: refs/heads/git_2b
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To c:/Users/IBM_ADMIN/git_1/
! [remote rejected] git_2b -> git_2b (branch is currently checked out)
error: failed to push some refs to 'c:/Users/IBM_ADMIN/git_1/'
8 Answers
Joseph Damiani
1,066 PointsI have the solution. You need to notice that Tommy was in the my_really_cool_project directory in the last video. In the Pushing and Pulling video he is in the our_clone_project directory. Make sure you use the cd .. to change directories.
Gabe Lopez
3,565 PointsSame problem here. I was able to get it to work by switching to the remote repository and changing the branch to anything other than master. The I switched back, ran the push command again and it was successful. I'm not quite sure why that worked and I couldn't reproduce the problem after it was successful.
From what I've read, it seems to have to do with bare vs non-bare repositories. Generally, you are not supposed to push to non-bare repositories (the kind we have been creating). I don't totally understand this yet, but http://bare-vs-nonbare.gitrecipes.de/ provides the best explanation I've been able to find so far.
Hope that helps at least a little! I'm still trying to figure this out myself...
David Clausen
11,403 PointsLooking it up it seems you can have a bare repository, the one we create by default "git init" is a working repository.
In a working repository people actively work on branches (master, new_feature), if you check out a branch "git checkout new_feature" its like checking out a book. So we checkout our origin branch "new_feature".
Then we went to our_clone_project and tried pushing to origin "new_feature" branch which was being checked out, by ourselves actually. Since someone is actively checking out that branch you can't push to it as a safety mechanism. (Two people commit changes at the exact same time as one is checked out)
So when you switched to the origin project and did "git checkout master" you were also un-checking out 'new-feature'.
A bare repository is a repository you share but don't actively work with, i.e Github. So no one can checkout any branch only pull/clone. This solves this problem and give you a central repository that you don't need to worry if someone checked it out.
Since we are only experimenting we are using two working repository and its a safety issue. So if you run into it again, make sure no-one is checking out that branch you are pushing too.
Kartik Kapoor
3,016 PointsHey, I was getting the same message.I went to my origin repository and switched to master and then ran the push command in the cloned repository.Then it worked for me.But I am confused as to why this is happening.
ian sobo
3,851 Pointsi love how there's this comment, and the exact opposite above. I dont get it.
Nathaniel Kolenberg
12,836 PointsHey guys,
Unfortunately, I'm getting the same issue no matter which branch I'm in (master or new_feature).
Is there any other way to solve this problem?
Thanks in advance!
Cheers,
Nathaniel
Dallas Davis
4,129 PointsI ran into the same problem, fixed it by switching branches as well. Just commenting to get email updates if and when an explanation pops up. :)
Konstantinos Pedarakis
21,301 PointsJust saw the video and i was lucky enough to see what is happening here as i had the exact same error. I see that many of you saw the video like 9 months ago or something but i like to share my solution so that it will be cleaner for you to understand.
so Ian de Jesus , the reason that an error occur in the spesific situation is because we, (including myself) are trying to push our changes to the remote repository (my_really_cool_project) when the imaginery user is actual cheched out in the same repository as well at the same time we actually pushing.
So, what you have to do is... You have to go to the imaginery user repository (my_really_cool_project) and do git checkout master
. then you go back to your repository(our_clone_project) and then do git push origin my_really_cool_project
this is what i found. Im not sure why is that happening, didnt find yet, but im working on it. Perhaps it is because for the sake of this example we are trying to set up differnet remote repositories on the same machine. this would't happening if we were working lets say on a real project and we were setting paths along the Internet.
Hope that i helped you!!!
Happy Coding!!!
Jasmine Frantz
8,299 PointsI am getting exactly the same message as the post. I tried everything on here but still getting an error message....
Vartan Good
8,755 PointsDavid Clausen's explanation's awesome.
guys just switch in your origin repository to master branch. then go "our_clone_project" and u can do your git push origin newFeature. u have this error if have checkout in your repositories same branch - in this situation we have conflict and this error.