Search code examples
gitbash

How do I loop through all of my Git repositories and update them?


I have a folder where I keep all of my Git repos. I usually just do git pull to get my changes, but now that I have over 50 repos it becomes a burden to have to do this for every folder.

How can I run a command that will loop through every repo and update it for me?


Solution

  • In Bash you can run this command which will loop through every repo in your working directory, stash your changes, fetch the origin and pull the latest commit.

    for d in */; do cd $d; git stash; (git pull &); cd ..; done
    

    Some things to note:

    • This will use your working branch in your repo
    • (git pull &) opens a subshell and executes in the background