Git cheat sheet

Git setup

If you're a first time Git user, set up your global Git configuration first:

git config --global user.name "John Doe"
git config --global user.email johndoe@example.com

Enabling color output is highly recommended:

git config --global color.ui auto

You can also create your own global .gitignore file in $HOME, and put rules for your editor temp files in there. Enable it like this:

git config --global core.excludesfile ~/.gitignore

By default, 'git push' without arguments pushes all local branches to existing branches with the same name on the remote. This is not what most users expect. It is recommended to change the 'push.default' setting to 'upstream', so only the current branch will be pushed to its upstream branch.

git config --global push.default upstream

ASF committers can set their Apache username, so they don't have to enter it with every commit:

git config credential.username <username>

Cloning

To clone the repository:

git clone https://git-wip-us.apache.org/repos/asf/lucy.git

Standard workflow

git checkout <branch>
git pull --rebase
[edit]
git commit
git push

Working with branches

Create and switch to a local branch:

git checkout -b <branch>

Push local branch to remote for the first time:

git push -u origin <branch>

Use the -u option to automatically setup the remote tracking configuration.

Checkout a remote tracking branch:

git checkout --track origin/<branch>

Delete a remote branch:

git push origin :<branch>

GitCheatSheet (last edited 2012-11-02 21:41:55 by nwellnhof)