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:
desktop$ git remote add laptop user@laptop:/path/to/repo
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):
desktop$ git checkout -b development --track laptop/development
or just simply (with modern git)
desktop$ git checkout --track laptop/development
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").
Can you not just git pull the remote branch from your laptop? Git will pull over http, ssh - many protocols. My git syntax is rather rusty, but something like…
Edit: Digging through memory and manuals, you may need to initially add the new remote with
git remote add ssh://remotestuff/
then you can
git checkout --track -b localBranchName remote/remoteBranch
to track the branch.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With