(1) On the desktop, clone the repo into a temp dir (where you will set all the branch labels the way you want them on the notebook). Let's use a (bare) --mirror
clone to make it non-tempting to fuss with a work directory, and to save some space, while also copying all refs in one swell foop:
desktop$ mkdir /tmp/for_notebook; cd /tmp/for_notebook # or similar
desktop$ git clone --mirror /path/to/repo
Now that you have /tmp/for_notebook/repo.git
(--bare
and/or --mirror
tends to add .git
), set all the branch labels in this clone to match where they were on the notebook:
desktop$ cd repo.git # i.e., /tmp/for_notebook/repo.git
desktop$ for refname in # ok, now see below
Here's where you can either do things manually, or by script. If there's a small number of branches you can just list them manually:
desktop$ for refname in fix/issue1 master; do
> git update-ref refs/heads/$refname refs/remotes/notebook/$refname
> done
If there are many, you can automate this with git for-each-ref
, but it will give you long(ish, might as well just use full) names that require a little more shell scripting:
desktop$ for fullname in $(git for-each-ref \
> --format '%(refname)' refs/remotes/notebook/); do
> refname=${fullname#refs/remotes/notebook/}
> git update-ref refs/heads/$refname $fullname
> done
At this point git branch
should give you just the branches you expect, but if there are extras, you can delete them with git branch -d
.
(2) Now clone this to the notebook, as a new repo:
notebook$ git clone ssh://desktop.name//tmp/for_notebook/repo.git repo
This will no doubt set up the master
branch already; you just need to add the other branches. Re-updating master
is harmless, so, same idea as before, except the remotes are now origin/*
instead of for_notebook/*
:
notebook$ for fullname in $(git for-each-ref \
> --format '%(refname)' refs/remotes/origin/); do
> refname=${fullname#refs/remotes/origin/}
> git update-ref refs/heads/$refname $fullname
> done
You probably want to tweak the config at this point, etc., so that you don't have desktop
and /tmp/for_notebook/repo.git
as origin
. (I usually do this by just editing .git/config
directly.) Compare with the notebook's original repo .git/config
as needed.
(The old reflog is gone now, and any git stash
es you had saved, as those were all local refs that did not get copied to desktop
.)