I am working with 5 repos that I have cloned in my development environment. When I want to update a git repo, I enter the folder /home/adrian/repo1/ and do:
git checkout master git pull origin master
But then, every morning I have to do the same thing for the other 4 repos. This is quite troublesome.
Can I put this in a shell script? I mean, if I write these git commands in the shell script, and run it, will I be able to update all the repos?
I was thinking of writing something like this...
cd repo1
git checkout master
git pull origin master
cd ..
cd repo2
git checkout master
git pull origin master
cd ..
(i'm on linux)
Edit: Maybe this is more challenging than what I thought. Most times when I do "git pull origin master", i get erorrs like "Your local changes to .... would be overwritten by merge." So i have to enter into the respective branch and stash the stuff..
Edit 2:
What I'm thinking of doing is, if a conflict happens, ignore it and go to the next repo
cd repo1
git checkout master
git pull origin master
(if there is conflict, ignore and go to the next line but dont stop here)
cd ..
cd repo2
git checkout master
git pull origin master
cd ..
but i dont know how to write the thing in parenthesis.
I know I'm really late to the party on this question, but here's a little shell script I wrote for this exact purpose.
It probably seems very amateurish, but that's because it probably is! I mainly wrote this to help myself learn bash, but I hope it helps you (or whoever may be reading this right now).
There's a lot of unnecessary fluff on this that you can remove (like changing the color of the text, and listing the repositories with uncommitted changes) that you can remove.
The link to the repo is here
I would suggest to manage the update of all the repos with a cron script.
Here is an example script for auto update base to their upstream.
First, I recommend against using
git pull
. Instead, create a safergit up
alias:See this answer for an explanation of
git up
.Then you can safely script it:
As I have many git repo's checked out locally for work, i decided to write a more detailed script to update all the repo's (bash script will search for git repos up to 3 folders deep to update. It will then do a git stash, fetch, rebase, and stash pop the local changes back. Script for me runs in git bash shell on windows.