[ACCEPTED]-Copying git local branch between machines?-git

Accepted answer
Score: 14

Let's assume that you have both repository 33 on 'desktop' machine and repository on 'laptop' machine 32 set up in such way that you can fetch on 31 'desktop' from 'laptop' and vice versa (e.g. via 30 SSH, or via git:// protocol i.e. via git-daemon, or 29 perhaps via simple HTTP).

Both 'desktop' and 28 'laptop' machine have 'master' branch, and 27 additionally 'laptop' machine has 'development' branch.

Let 26 first set up remote shortcut, and remote-tracking branches using git remote:

desktop$ git remote add laptop user@laptop:/path/to/repo

This 25 would set up remote named 'laptop' and remote-tracking 24 branches: 'laptop/master' (or to be more 23 exact 'refs/remotes/laptop/master') which 22 follows branch 'master' on 'laptop', and 21 'laptop/development' which follows branch 20 'development' on 'laptop'.

Then you need 19 to create local branch 'development' on 'desktop', which 18 would follow (track) remote-tracking branch 17 'laptop/development' (as you can't develop 16 on remote-tracking branches):

desktop$ git checkout -b development --track laptop/development

or just simply 15 (with modern git)

desktop$ git checkout --track laptop/development

See git-branch manpage for details.

This 14 setup allows to use simply "git pull" when 13 on branch 'development' while on 'desktop', and 12 git would automatically fetch all changes 11 fro repository at 'laptop' into 'laptop/master' and 10 'laptop/development' remote-tracking branches, and 9 then try to merge 'laptop/development' into 8 'development' (current branch) -- which 7 would usually result in fast-forward, i.e. simply moving 6 'development' branch.

Then you can create 5 similar setup on 'laptop' (although setting 4 up existing branch 'development' on 'laptop' to 3 track 'desktop/development' might require 2 editing config file directly or via "git 1 config").

Score: 2

Can you not just git pull the remote branch 6 from your laptop? Git will pull over http, ssh 5 - many protocols. My git syntax is rather 4 rusty, but something like…

Edit: Digging 3 through memory and manuals, you may need 2 to initially add the new remote with

git remote add ssh://remotestuff/

then 1 you can

git checkout --track -b localBranchName remote/remoteBranch

to track the branch.

Score: 0

You can copy the repo in a usb stick, plug 2 it in the second laptop/pc, cd to the repo 1 and do:

git remote add usbstick path/to/repo/in/usbstick
git fetch usbstick
git branch branch_name usbstick/branch_name

More Related questions