To get all the changes from all the branches, use git fetch --all . And if you'd like to clean up some of the branches that no longer exist in the remote repository, git fetch --all --prune will do the cleaning up!
Thanks for the lead! git fetch -all fetches all branches of all remotes. git fetch origin fetches all branches of the remote origin .
Git shallow clone lets you pull down just the latest commits, not the entire repo history. So if your project has years of history, or history from thousands of commits, you can select a particular depth to pull.
Run the following from the parent directory, plugins
in this case:
find . -type d -depth 1 -exec git --git-dir={}/.git --work-tree=$PWD/{} pull origin master \;
To clarify:
find .
searches the current directory-type d
to find directories, not files-depth 1
for a maximum depth of one sub-directory-exec {} \;
runs a custom command for every findgit --git-dir={}/.git --work-tree=$PWD/{} pull
git pulls the individual directoriesTo play around with find, I recommend using echo
after -exec
to preview, e.g.:
find . -type d -depth 1 -exec echo git --git-dir={}/.git --work-tree=$PWD/{} status \;
Note: if the -depth 1
option is not available, try -mindepth 1 -maxdepth 1
.
ls | xargs -I{} git -C {} pull
To do it in parallel:
ls | xargs -P10 -I{} git -C {} pull
A bit more low-tech than leo's solution:
for i in */.git; do ( echo $i; cd $i/..; git pull; ); done
This will update all Git repositories in your working directory. No need to explicitly list their names ("cms", "admin", "chart"). The "cd" command only affects a subshell (spawned using the parenthesis).
Actually, if you don't know if the subfolders have a git repo or not, the best would be to let find
get the repos for you:
find . -type d -name .git -exec git --git-dir={} --work-tree=$PWD/{}/.. pull origin master \;
The PowerShell equivalent would be:
Get-ChildItem -Recurse -Directory -Hidden -Filter .git | ForEach-Object { & git --git-dir="$($_.FullName)" --work-tree="$(Split-Path $_.FullName -Parent)" pull origin master }
I use this one:
find . -name ".git" -type d | sed 's/\/.git//' | xargs -P10 -I{} git -C {} pull
Universal: Updates all git repositories that are below current directory.
This should happen automatically, so long as cms, admin and chart are all parts of the repository.
A likely issue is that each of these plugins is a git submodule.
Run git help submodule
for more information.
EDIT
For doing this in bash:
cd plugins
for f in cms admin chart
do
cd $f && git pull origin master && cd ..
done
The mr
utility (a.k.a., myrepos
) provides an outstanding solution to this very problem. Install it using your favorite package manager, or just grab the mr
script directly from github and put it in $HOME/bin
or somewhere else on your PATH
. Then, cd
to the parent plugins
folder shared by these repos and create a basic .mrconfig
file with contents similar to the following (adjusting the URLs as needed):
# File: .mrconfig
[cms]
checkout = git clone 'https://<username>@github.com/<username>/cms' 'cms'
[admin]
checkout = git clone 'https://<username>@github.com/<username>/admin' 'admin'
[chart]
checkout = git clone 'https://<username>@github.com/<username>/chart' 'chart'
After that, you can run mr up
from the top level plugins
folder to pull updates from each repository. (Note that this will also do the initial clone if the target working copy doesn't yet exist.) Other commands you can execute include mr st
, mr push
, mr log
, mr diff
, etc—run mr help
to see what's possible. There's a mr run
command that acts as a pass-through, allowing you to access VCS commands not directly suported by mr
itself (e.g., mr run git tag STAGING_081220015
). And you can even create your own custom commands that execute arbitrary bits of shell script targeting all repos!
mr
is an extremely useful tool for dealing with multiple repos. Since the plugins
folder is in your home directory, you might also be interested in vcsh
. Together with mr
, it provides a powerful mechanism for managing all of your configuration files. See this blog post by Thomas Ferris Nicolaisen for an overview.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With