OK so I’m tracking a remote repo on two machines so both have the master branch. I also made a local branch on my laptop called development. Is there a way for me to copy that local branch over to my desktop computer? I’d use my laptop but for some reason I’m having trouble with gdb and emacs…
Edit: This worked for me
git remote add laptop [username]@hostname:/path/to/repo
git fetch laptop
git checkout --track -b development laptop/development
git pull
Let’s assume that you have both repository on ‘desktop’ machine and repository on ‘laptop’ machine set up in such way that you can fetch on ‘desktop’ from ‘laptop’ and vice versa (e.g. via SSH, or via
git://protocol i.e. via git-daemon, or perhaps via simple HTTP).Both ‘desktop’ and ‘laptop’ machine have ‘master’ branch, and additionally ‘laptop’ machine has ‘development’ branch.
Let first set up remote shortcut, and remote-tracking branches using git remote:
This would set up remote named ‘laptop’ and remote-tracking branches: ‘laptop/master’ (or to be more exact ‘refs/remotes/laptop/master’) which follows branch ‘master’ on ‘laptop’, and ‘laptop/development’ which follows branch ‘development’ on ‘laptop’.
Then you need to create local branch ‘development’ on ‘desktop’, which would follow (track) remote-tracking branch ‘laptop/development’ (as you can’t develop on remote-tracking branches):
or just simply (with modern git)
See git-branch manpage for details.
This setup allows to use simply “git pull” when on branch ‘development’ while on ‘desktop’, and git would automatically fetch all changes fro repository at ‘laptop’ into ‘laptop/master’ and ‘laptop/development’ remote-tracking branches, and then try to merge ‘laptop/development’ into ‘development’ (current branch) — which would usually result in fast-forward, i.e. simply moving ‘development’ branch.
Then you can create similar setup on ‘laptop’ (although setting up existing branch ‘development’ on ‘laptop’ to track ‘desktop/development’ might require editing config file directly or via “git config”).