Here we will show you how to track all remote branches in GIT and get them all at once in your local.
Below is the demo of a git where there are several branches and each branches there are some code.
https://github.com/Santoshah/firebase-auth
To get this clone we simply run the command.
git clone https://github.com/Santoshah/firebase-auth
Above command is going to give checkout default branch which in this case is a `master`.
santoshshah@192 firebase-auth % git branch
* master
Even if you run above command this will only show master branch from the git clone. So, in order to trace all remove branch you would need to run below command:-
git branch -r
This will get all branches available in that branch.
santoshshah@192 firebase-auth % git branch -r
origin/HEAD -> origin/master
origin/lesson-10
origin/lesson-11
origin/lesson-12
origin/lesson-13
origin/lesson-14
origin/lesson-15
origin/lesson-17
origin/lesson-18
origin/lesson-19
origin/lesson-20
origin/lesson-22
origin/lesson-23
origin/lesson-3
origin/lesson-4
origin/lesson-5
origin/lesson-6
origin/lesson-7
origin/lesson-8
origin/lesson-9
origin/master
So now you know what other branches are available in that git but still you don’t have those branch in your local. In ordre to get them in your local you need to run below wired bash script command.
You can track them manually as well by entering below command and replace `<branch>` with the branch name available in remote branches.
git branch --track <branch>
However you wish to get all the branches at once run the below bash script command.
for i in $(git branch -r | grep -vE "HEAD|master"); do git branch --track ${i#*/} $i; done
git checkout master
git pull
Update information about the remote branches on your local system:
git fetch --all
Update information about the remote branches on your local computer and update local branches:
git pull --all
Git tips and tricks - Santosh Kumar Shah
[…] Track all remote branches GIT […]