One of the nice things about git is its expandability, through aliases and scripts. To some extent, using these can hide the complexities of git and make it work more like svn. So I'm attaching a few of the ones I've developed so far. They're written in bash and so should work on any *nix.

Aliases can be created with:
    git config alias.my-alias-name "what you want it to do"
Something like
    git config --global alias.my-alias-name "what you want it to do"
will make the alias globally available, whereas the former one is specific to a repository. Some dumb but useful aliases are:
    git config --global alias.co checkout
    git config --global alias.br branch
    git config --global alias.ci "commit -a"
These just save typing. I.e., you can do things like:
    git co master
    git br
    git ci
instead of the longer things.

Note that you can also add aliases by editing the .gitconfig file directly: Either the global one in your home directory, or the local .git/config file in a repo.

This one is more useful:
git config alias.addst '!kate status.20x && git add status.20x && git commit --amend' The leading "!" means: Run this as a script. This is intended to be used when you're porting something to branch. It opens kate (substitute your favorite editor) on status.20x, stages it when you are done, and then amends the last commit (we're assuming this is the one you backported), thus adding status.20x to the commit, but also allowing you a chance to edit the commit message.

More complex tasks can be done by writing standalone scripts and then calling them:
    git config --global alias.mycmd '!my-script.sh'
The scripts below can be aliased this way.

The git-up script is simple and stupid: It just runs "git pull --rebase", but it checks to make sure that the current branch is one you might want to do this on first. Of course that can be changed.

The git-push-* scripts push the current branch to master or 2.0.x on git.lyx.org, as the case might be. First, however, they show you the log messages for the commits you're about to push, and ask if you really want to do that.

These would be set up via:
    git config --global alias.push-master '!git-push-master'
etc. Of course the scripts need to be in the path and made executable for that version to work.

Richard

#!/bin/bash

REMOTE="origin";
RBRANCH="2.0.x";
BRANCH=$(git br | grep '^\*' | cut -d' ' -f2);

COMMITS=$(git push -n $REMOTE $BRANCH:$RBRANCH 2>&1 | tail -n 1 | sed -e 's/^ 
*//' -e 's/ .*//');

git log $COMMITS;

#Do we want to go ahead?
echo
echo "Do you want to push these commits to $RBRANCH?"
select answer in Yes No; do
        if [ "$answer" != "Yes" ]; then
                exit 0;
                break;
        else 
                break;
        fi
done

git push $REMOTE $BRANCH:$RBRANCH
#!/bin/bash

REMOTE="origin";
RBRANCH="master";
BRANCH=$(git br | grep '^\*' | cut -d' ' -f2);

COMMITS=$(git push -n $REMOTE $BRANCH:$RBRANCH 2>&1 | tail -n 1 | sed -e 's/^ 
*//' -e 's/ .*//');

git log $COMMITS;

#Do we want to go ahead?
echo
echo "Do you want to push these commits to $RBRANCH?"
select answer in Yes No; do
        if [ "$answer" != "Yes" ]; then
                exit 0;
                break;
        else 
                break;
        fi
done

git push $REMOTE $BRANCH:$RBRANCH
#!/bin/bash

CURRENT=$(git br | grep '*' | sed -e 's/\* //');

if [ -z "$CURRENT" ]; then
        echo "Can't find current branch!";
        exit 1;
elif [ $CURRENT="master" ]; then 
        CMD="git pull --rebase";
elif [ $CURRENT="2.0.x" ]; then 
        CMD="git pull --rebase";
else
        echo "Do not know what to do with branch '$CURRENT'.";
        exit 1;
fi

echo Running: $CMD;
$CMD;

Reply via email to