In this post, we will see how to fetch all Git branches. Sometimes, we need to clone a repository that has lots of branches but it will only show you the master
the main
branch when you run the git branch command. Let’s see how to fetch all the Git branches.
Solution 01 git branch -r
The -r
or --remotes
option is used to list remote-tracking branches. Run the below command to see all the branches in your terminal.
git branch -r
Then, you can check them out as local branches with:
git checkout -b LocalName origin/remotebranchname
Solution 02 git branch -a
The -
a or --all
option is used to list both remote-tracking branches and local branches. Run the below command to see all the branches in your terminal.
git branch -a
Solution 03 Using Bash Script
Using the bash script all remote branches will be added to the git track so you don’t need to run the above command everytime. You need to run git branch
command to see all branches. Run the below command to see all the branches in your terminal.
for i in $(git branch -r | grep -vE "HEAD|master"); do git branch --track ${i#*/} $i; done
Now, run the git branch to see all branches.
Additionally, read our guide:
- Laravel: Blade Switch Case Statement Example
- Laravel: Switch Case Statement In Controller Example
- Laravel Paypal Integration Tutorial With Example
- 2fa Laravel With SMS Tutorial With Example
- How To Use Where Date Between In Laravel
- How To Add Laravel Next Prev Pagination
- Laravel Remove Column From Table In Migration
- Laravel: Get Month Name From Date
- Laravel: Increase Quantity If Product Already Exists In Cart
- How To Update Pivot Table In Laravel
- How To Install Vue In Laravel 8 Step By Step
- How To Handle Failed Jobs In Laravel
- Best Ways To Define Global Variable In Laravel
- How To Get Latest Records In Laravel
- How To Break Nested Loops In PHP Or Laravel
- How To Pass Laravel URL Parameter
- Laravel Run Specific Migration
- Laravel Notification Tutorial With Example
- How To Schedule Tasks In Laravel With Example
- Laravel Collection Push() And Put() With Example
That’s it from our end. We hope this article helped you fetch all git branches.
Please let us know in the comments if everything worked as expected, your issues, or any questions. If you think this article saved your time & money, please do comment, share, like & subscribe. Thank you for reading this post 🙂 Keep Smiling! Happy Coding!