Skip to content

Instantly share code, notes, and snippets.

@xenophonf
Created April 5, 2016 15:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xenophonf/9df09e47a8629bb789ffbb94c7d17e42 to your computer and use it in GitHub Desktop.
Save xenophonf/9df09e47a8629bb789ffbb94c7d17e42 to your computer and use it in GitHub Desktop.
GitHub fork management scripts
#!/bin/sh
## kind of any ugly hack
read checkout repo upstream<<EOF
`grep '^'$1 ./forks`
EOF
## clone the repository
rm -rf $checkout
git clone $repo
## ...we came in
cd $checkout
## configure the upstream remote
git remote add upstream $upstream
## everybody remember where we parked
origbranch=`git branch | fgrep '*' | awk '{print $2}'`
## set up all of the remote-tracking branches
for branch in `git branch -r | grep -v '\(^ upstream/\|^ origin/HEAD\)' | sed -e 's/ origin\///' | fgrep -v $origbranch`; do
git checkout -b $branch --track origin/$branch
done
## isn't this where...
git checkout $origbranch
cd ..
## leave updating the remote-tracking branches for another script
#./update-fork $checkout
#!/bin/sh
checkout="`basename $1`"
repo="git@github.com:$1"
upstream="git@github.com:$2/$checkout"
## clone the repository
git clone $repo
## ...we came in
cd $checkout
## configure the upstream remote
git remote add upstream $upstream
git fetch upstream
## everybody remember where we parked
origbranch=`git branch | fgrep '*' | awk '{print $2}'`
## set up all of the remote-tracking branches
for branch in `git branch -r | grep '^ upstream' | sed -e 's/ upstream\///'`; do
if [ "$branch" != "$origbranch" ]; then
git checkout -b $branch --track origin/$branch
else
## the default branch (usually `master` or `develop`) is
## already set up to track its origin
git checkout $branch
fi
git merge --ff-only upstream/$branch
git push
done
## isn't this where...
git checkout $origbranch
cd ..
## add this repo to the list of checked out forks
echo $checkout $repo $upstream >> forks
#!/bin/sh
fork=$1
## make sure the fork exists
if [ ! -d $fork ]; then
./setup-fork-again $fork
fi
## ...we came in?
cd $fork
## sync with the upstream repo
branches=$(git fetch upstream 2>&1 | tee /dev/fd/2 | fgrep .. | awk '{print $2}')
## everybody remember where we parked
origbranch=`git branch | fgrep '*' | awk '{print $2}'`
## sync the branches updated upstream
for branch in $branches; do
git checkout $branch
git merge --ff-only upstream/$branch
git push
done
## isn't this where...
git checkout $origbranch
cd ..
#!/bin/sh
while read checkout repo upstream
do
./update-fork $checkout
done < ./forks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment