1

I cloned a project over ssh, made some changes, commit it, and then trying to push changes back (by $> git push), but I'm getting an error: "remote: error: refusing to update checked out branch: refs/heads/master".

Why is that, and how to fix it?

Chris
  • 54,599
  • 30
  • 149
  • 186
nukl
  • 10,073
  • 15
  • 42
  • 58
  • 1
    The same error is mentioned in http://stackoverflow.com/questions/2816369/git-push-error-remote-rejected-master-master-branch-is-currently-checked-ou and http://stackoverflow.com/questions/2670680/git-basic-workflow. Are they relevant? – Synesso Apr 13 '11 at 07:50

3 Answers3

6

You should only push to bare repositories

Community
  • 1
  • 1
Sean
  • 671
  • 5
  • 11
0

It seems like you've cloned a personal repository (where files are checked out etc.).

You can't push back to the currently checked out branch on the remote, which is origin/master in your case.

But you can create a new branch in your clone and push that one back.

matthias.lukaszek
  • 2,200
  • 1
  • 23
  • 33
0

There might be some changes applied to the remote branch after you checked it out. If you are talking about single commit you made, and remote branch is master, then do:

git fetch origin

to fetch most recent changes

git rebase origin/master

to put your changes on top, and finally

git push origin master

The last command can be reduced to the one you used, but it is usually a good habit to specify where exactly you push the changes on the current branch.

Ruslan Kabalin
  • 6,580
  • 2
  • 28
  • 20