I created mirrors of my git repositories into GitHub and Dropbox. And I sometimes use git tag to reset a state of a branch after hard manipulation by multiple merge/rebase like the following (though it's possible to use git reflog to know what commit is the point to reset manipulation, it's somewhat hard to find out about it, so that I prefer to using git tag):
git tag tmp git merge experimental git merge eccentric git merge extreme git rebase -i HEAD~10 git reset --hard tmp
After doing some work, I do git push --all and git push --tags for each remote (= GitHub and Dropbox) to mirror (these commands are executed as a single command, like git mirror). But I often forget that I created temporary tags, and I don't want to publish such tags to outside. So I have to delete temporary tags for each remote, but it's bored work. I don't want to type for i in $(git remote); do git push $i :temporary-tag; done, etc.
So today I added an alias for this routine work into my gitconfig, as follows (see also: An easy way to write your own git subcommand in gitconfig) :
pushall = <<<
for i in $(git remote)
do
echo "# git push $i $@"
git push "$i" "$@"
done
>>>With pushall, the routine work can be simplified as follows:
git pushall :temporary-tag
As I described before, it's possible to write your own git subcommand with shell script and to embed it in gitconfig. But it's hard to do so. For example, the following shell script lists the recent commits on a given branch (default: HEAD) up to a given count (default: 10 commits):
n=10
1="${1:-$n}"
if [ "${1##[0-9]*}" != "" ]
then
t="$1"
1="${2:-$n}"
2="$t"
fi
git --no-pager log --pretty=oneline --reverse -"$1" "${2:-HEAD}"To embed this script into gitconfig, you have to write as follows:
[alias]
lr = "!$SHELL -c '\
n=10\n\
1=\"${1:-$n}\"\n\
if ! [ \"${1##[0-9]*}\" = \"\" ]\n\
then\n\
t=\"$1\"\n\
1=\"${2:-$n}\"\n\
2=\"$t\"\n\
fi\n\
git --no-pager l1 --reverse -\"$1\" \"${2:-HEAD}\"\n\
' __dummy__"But it's hard to write by hand! So I wrote a script gitconfig-compiler.rb to easily embed shell script as follows:
[alias]
lr = <<<
n=10
1="${1:-$n}"
if ! [ "${1##[0-9]*}" = "" ]
then
t="$1"
1="${2:-$n}"
2="$t"
fi
git --no-pager l1 --reverse -"$1" "${2:-HEAD}"
>>>To convert gitconfig with the above script, use the following command:
ruby gitconfig-compiler.rb <dot.gitconfig.in >~/.gitconfig