Skip to content

Instantly share code, notes, and snippets.

@darxriggs
Created December 13, 2014 12:30
Show Gist options
  • Save darxriggs/c02afc0fb64ee1306922 to your computer and use it in GitHub Desktop.
Save darxriggs/c02afc0fb64ee1306922 to your computer and use it in GitHub Desktop.
git - pruning locale tags that don't exist on the remote repo
#!/bin/bash -ue
show_branches_and_tags() {
echo "### branches & tags ###"
git branch -a
git tag -l
echo "#######################"
}
rm -rf remote-repo
rm -rf local-repo
echo
echo "###################################################"
echo "# create remote-repo with branches, commits, tags #"
echo "###################################################"
mkdir remote-repo
pushd remote-repo > /dev/null
git init .
touch remote-file-1
git add remote-file-1
git commit -m 'remote-file-1'
git tag remote-tag-1
git tag remote-annotated-tag-1 -a -m 'description'
git tag remote-tag-2
git tag remote-annotated-tag-2 -a -m 'description'
git branch remote-branch-1
git branch remote-branch-2
show_branches_and_tags
popd > /dev/null
echo
echo "##################################################"
echo "# create local-repo with branches, commits, tags #"
echo "##################################################"
git clone --single-branch --branch master file:///$(pwd)/remote-repo local-repo
pushd local-repo > /dev/null
touch local-file-1
git add local-file-1
git commit -m 'local-file-1'
git tag local-tag-1
git tag local-annotated-tag-1 -a -m 'description'
git tag local-tag-2
git tag local-annotated-tag-2 -a -m 'description'
git branch local-branch-1
git branch local-branch-2
show_branches_and_tags
popd > /dev/null
echo
echo "#############################################"
echo "# fetch (prune) remote-repo into local-repo #"
echo "#############################################"
pushd local-repo > /dev/null
#git fetch --prune --force
git fetch --prune --force origin refs/heads/master:refs/remotes/origin/master
git fetch --prune --force origin refs/tags/*:refs/tags/* # but if also fetches tags not on the master branch!
git checkout --force -B master origin/master
show_branches_and_tags
ls -l
popd > /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment