Reputation: 30332
My workflow is basically:
Now I want to synchronise the changes with my desktop. Trying git push desktop.local:~/my-repo
will fail, because the master branch is already checked out. I know of two solutions to this:
Create a third, bare repository in another directory on my PC and update both working copies from there. But a single central repository with two working copies checked out sounds like... SVN! Except clumsier, because I can't just use svn update
and svn commit
to synchronise with this central repository — extra steps are required to actually update the central repo from changes committed to a working copy in Git.
Push to a separate branch and merge that branch in on my desktop working copy. This isn't too bad, but...
...what I don't understand is this: if I just SSH to the desktop PC and issue git pull laptop.local:~/my-repo
, it works! It pulls the committed changes in and updates the checked out master branch, no questions asked. Why can't git push
do this itself?
So here's my question: is there a command that works the same as ssh
-ing in to my desktop PC and issuing a pull
?
Upvotes: 3
Views: 3426
Reputation: 22596
The problem is when you are trying to push you are doing 2 actions at the same time. The first one is to update git tree and the second one is to update the working directory on your laptop. So there is a kind of implicit 'checkout' in the push process and git refuse to do it and it's right. Imagine what will happen if someone was actually working on your desktop PC. When you do an SSH things are different, you are in your working directory, you are responsible for everything you do, and so, can do what ever you want , removing file , "pulling". So it seems normal in a way, that pushing doesn't allow you (by default) to mess up the remote computer.
If you are setting the receive.denyCurrentBranch to ignore , you can push but you still have to "synchronize" your working directory with the "latest" version of the code (the one you just pushed). That mean you still have 2 commands to run one on each computer
If you really want to run only one command use the power of the shell and create an alias which do a git pull from the Desktop computer
alias remote_pull=ssh <desktop> "cd <path>; git pull"
Upvotes: 2
Reputation: 5938
You can set receive.denyCurrentBranch
to warn to allow pushing to your desktop PC. However, this is dangerous. If there are some commits in your desktop PC, this push will cause confuse.
The following is manual of receive.denyCurrentBranch
for your reference.
receive.denyCurrentBranch
If set to true or "refuse", receive-pack will deny a ref update to
the currently checked out branch of a non-bare repository. Such a
push is potentially dangerous because it brings the HEAD out of
sync with the index and working tree. If set to "warn", print a
warning of such a push to stderr, but allow the push to proceed. If
set to false or "ignore", allow such pushes with no message.
Defaults to "refuse".
Upvotes: 2