Skip to content

Git Local Branch Transfer

how to copy branches across local repos

this is just a simple trick I use to transfer branches in local repos, without the need for a remote server this becomes handy when I have essentially the same project repos, but released by two different vendors (like linux-kernel: mainline, stable, next ...), and creating a remote repo isn't an option e.g project is too big or being offline.

first you have to install ssh server:

doas pacman -S openssh

and start it:

doas systemctl start ssh

you almost done, all you need is to add the proper origin of the repo that needs the target branch, in the repo that contains it:

git remote add local_tree `id -un`@localhost:~/path/to/receiver_repo

finally push to that local origin:

git checkout <target_branch>
git push local_tree <target_branch>

now you should find your branch in both of your repos, I prefer this method because it is much faster, than transfering through the network. note your repos should have the same base tree, for that to work properly.