Home » Git Fetch All Branches

Git Fetch All Branches

Last updated on May 28, 2022 by

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:

  1. Laravel: Blade Switch Case Statement Example
  2. Laravel: Switch Case Statement In Controller Example
  3. Laravel Paypal Integration Tutorial With Example
  4. 2fa Laravel With SMS Tutorial With Example
  5. How To Use Where Date Between In Laravel
  6. How To Add Laravel Next Prev Pagination
  7. Laravel Remove Column From Table In Migration
  8. Laravel: Get Month Name From Date
  9. Laravel: Increase Quantity If Product Already Exists In Cart
  10. How To Update Pivot Table In Laravel
  11. How To Install Vue In Laravel 8 Step By Step
  12. How To Handle Failed Jobs In Laravel
  13. Best Ways To Define Global Variable In Laravel
  14. How To Get Latest Records In Laravel
  15. How To Break Nested Loops In PHP Or Laravel
  16. How To Pass Laravel URL Parameter
  17. Laravel Run Specific Migration
  18. Laravel Notification Tutorial With Example
  19. How To Schedule Tasks In Laravel With Example
  20. 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!

 
 

Leave a Comment