Reputation: 2975
I am new to Git and get bit confused (Just start to use it today). I have following issue. At work I have git repo and I clone it to my laptop. And at home I clone from my laptop to my Desktop PC.
Work Sever -> git clone -> Laptop -> git clone -> Desktop PC
So after I make some changes to source, I type following command 'git push'. As far as I understand I just push to changes to local repo. Then I try to 'push orgin master' I am getting following error:
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 289 bytes, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: error: refusing to update checked out branch: refs/heads/master
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 user_name@host:~/path/to/folder/.git
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'user_name@host:~/path/to/folder/.git'
In my Laptop i did not saw any changes. So what should I do in this case? What is proper way? Can you explain in more details? Thank you in advance for answers.
Upvotes: 0
Views: 163
Reputation: 239230
Read the error, it's giving you clear instructions in plain English.
Git won't push to a repo that has a working directory checked out to the branch you're trying to overwrite, because that is (presumably) somebody else's working directory, and they probably don't want you changing their repo while they're working on it.
Think of it this way: When you're working with Git, you're basically preparing a patch to apply to the currently checked out branch in order to move it from one state, A
, to another state, B
. You do this by making changes to the working directory, and staging them with git add
, and then committing them with git commit
to produce B
. If somebody is pushing to your repository and modifying the branch you're on, the state A
will constantly be changing, and your work will continually be invalidated. You're effectively trying to produce a patch to apply to a moving target. By default, Git refuses to allow you to put yourself into this situation.
You need to either make your laptop's repo a "bare" repo, or check out a different branch on your laptop before pushing, or, as the instructions say, set receive.denyCurrentBranch
to ignore or warn.
The best way of circumventing this situation is to, from your laptop, pull changes from your desktop to your laptop, instead of pushing them from your desktop.
Upvotes: 1