27
Nov/08
1

My git cheat sheet

In the last days I’ve spent several hours days understanding the concept of git. Now I need to write down some commands to be able to remember the commands which I don’t use every day when working with the git system.

The beginning: Fetch the contents of a repository:

:> git clone <url-of-repository>

Set your name and mail address (Will be used in commits):

:> git config user.email user@email.com
:> git config user.name 'John Doe'

Automatically merge local and remote branches:

:> git config branch.autosetupmerge true

The options set above only count for the current git repository (Stored in .git/config). To set the options globally for all repositories you use you need to create a .gitconfig file in your home directory. Adding the parameter –global to the config commands tells git to store these options in your ~/.gitconfig file.

Create a new remote branch on the base of an existing remote brach:

:> git push origin master:refs/heads/my_new_branch

Sync the new remote branch with a new local branch:

:> git checkout --track -b my_new_local_branch origin/my_new_branch

List all available branches (local and remote):

:> git branch -a

Delete a remote branch:

:> git push origin :refs/heads/my_branch

Change the current branch:

:> git checkout my_new_local_branch

Refresh the branch (get changes from remote):

:> git pull

Revert the uncommited changes in the current local branch (The dot can be replaced by a single filename):

:> git checkout .

Sometimes it’s harder, then try:

:> git reset --hard

Save the changes in the current branch to another branch (in this case the master) as diff:

:> git format-patch master

Each commit will result in a single file

Some pages which helped me out starting with git:

Filed under: Open Source
Comments (1) Trackbacks (0)
  1. LaMiNo Gravatar
    13:09 on June 27th, 2009

    Also useful:

    Start tracking the new branch

    git checkout –track -b new_feature_name origin/new_feature_name

    This means that when you do pulls that it will get the latest from that branch as well.

No trackbacks yet.