I have 2 local git archives in /a and in /b which were cloned from remotes/origin.
There is a new branch z on /b
How can I track and fetch branch z from archive /a ?
I tried this:
cd /a
git remote add b /b
This creates 2 config entries, but I did not manage to fetch something or to list remote branches on /a that would show the branches on /b
After trying different things I found the following that works:
1) git remote show b lists all the remote branches in b
2) I can fetch using this syntax:
git fetch file:///a/ z
Other things that also work:
$ cd /b
$ git checkout -b z
Switched to a new branch 'z'
$ git pull b z
But those commands still dont work and I cannot understand why:
git branch -a
does not list the remote branches in b (onlz the ones in origin are shown)
git checkout -t b/z
Does not checkout anything but returns an error message
So far you’ve only added b as a remote. You can try
git branch -ato list your remote branches after you’ve fetched them.Here’s the commands to checkout the z branch from b:
The
-t(or--track) creates a tracking branch, otherwise you’ll be in detached head state.Then you should see:
For anyone unclear on the steps involved, here’s what I did:
create origin
clone ‘a’ and add some content
clone ‘b’ and add more content on new branch
Add ‘b’ as a remote to ‘a’
I’ve put the above commands into a script so you can test it out yourself.