tags:

views:

249

answers:

2

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

+1  A: 

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.

Adam Wright
I get "fatal: git checkout: updating paths is incompatible with switching branches/forcing
gct
Rather hoping someone comes along with a better branching answer than this. I do find the git syntax and manuals to be largely inscrutable, which has spawned a huge industry of git "tutorials" that all differ slightly.
Adam Wright
@gct: The "updating paths is incompatible..." error typically means you have local changes in your current branch. Those changes need to be removed prior to checking out the new repo. If you need to keep them, you could `git stash` then `git checkout` and finally `git stash apply`.
Tim Henigan
No local changes unfortunately...
gct
+2  A: 

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").

Jakub Narębski
Is not '--track' unnecessary? The docs say that "this behavior is the default when the start point is a remote branch".
Casey
It is probably unnecessary, at least in first case (with explicit '-b' to start new branch), depending on `branch.autosetupmerge` (defaults to true).
Jakub Narębski