One of the nice things about git, is the ability to work in a distributed manor. Instead of having to have a central repository for your source code, you can create a copy of your repository and do work, while sharing the changes, on any number of machines. Often, when a few developers share code, they still use git with a central repository. There isn’t anything wrong with this, but sometimes, I find myself wanting to set something like this when I only want to share code between a couple computers where I am the only developer. In this case, I don’t need 3 copies of the code. I want to be able to push or pull changes between each of the machines without having to push to a 3rd repository.
So, you might try the following steps:
# on the 1st machine > git init . > # make some code changes > git add ... > git commit
# 2nd machine > git clone <1st machine ref> > # make some changes > git commit > git push # here is the problem
When you push from the 2nd machine to the 1st, the HEAD on the 1st machine is updated. The problem is that your working copy is NOT updated. To fix this, there are two solutions.
Mediocre, recover from doing the push solution:
# warning, the following will destroy any local changes you had made. > git reset --hard HEAD
If you had made changes on the 1st machine and forgot to commit them, you’d need to stash them, check out to a branch, or whatever.
Better way, avoid the reset all together
# on the 2nd machine > git push origin master:refs/heads/tmp_branch_name
# on the 1st machine > git merge tmp_branch_name > git branch -d tmp_branch_name
Another solution would be to add a remote on the 1st machine that points to the 2nd machine. Then each machine can just pull from the other rather than doing any pushes at all.