Skip to content

Instantly share code, notes, and snippets.

@shoaibi
Created June 25, 2015 15:37
Show Gist options
  • Select an option

  • Save shoaibi/ba13c6ed1ecb2e45e8bb to your computer and use it in GitHub Desktop.

Select an option

Save shoaibi/ba13c6ed1ecb2e45e8bb to your computer and use it in GitHub Desktop.
Update git repository's origin
#!/bin/bash
origBranch=$(git rev-parse --abbrev-ref HEAD)
upstreamBranch="$origBranch"
E_BADARGS=65
if [ $# -ne 2 -o $# -ne 1 ]; then
echo "Usage: $0 {new_origin} [{upstreamBranch}]"
exit $E_BADARGS
elif [ "x$2" != "x" ]; then
upstreamBranch="$2"
fi
git remote rename origin old
git remote add origin $1
git remote -v
# test and make sure the DreamHost origin works properly for fetch and push
git remote rm old
git branch --set-upstream-to=origin/"$upstreamBranch" "$origBranch"
git commit -am "Updated origin to $1"
git pull -u
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment