User:CaritasUbi/Git how-to

This page consists of helpful hints from my own experience with Git.

To edit the global config file
Mine looks like this:

[user] name = My Name email = My.Name@myserver.com [alias] log1 = log --pretty=format:\"%h - %an, %ad %ar : %s\" --date short -10

To create an alias from a command line
For example, to create an alias for a short-form log:

That log option creates output that looks like this:

42df7d8 - My Name, 2013-03-06 20 minutes ago : Explicit true causes MEH to be cleared 95ee118 - My Name, 2013-02-28 6 days ago : LuAnne's image 0fa3e90 - My Name, 2013-02-28 6 days ago : Moved to Eclipse project 7df80ac - My Name, 2013-02-28 6 days ago : captured sample timings for remaining time estimator 2efe9da - My Name, 2013-02-27 7 days ago : Renamed properties file d368013 - My Name, 2013-02-26 8 days ago : Successful result of downgrade (test03 part C) ece4f85 - My Name, 2013-02-26 8 days ago : First successful run of upgrade (test3 part b) 8b1c493 - My Name, 2013-02-26 8 days ago : Successful priming run ad6a191 - My Name, 2013-02-26 8 days ago : Initial push of split scripts bdad4eb - My Name, 2013-02-26 8 days ago : Failed test 3 part b

From the same branch
To get a specific revision:

From another branch
A typical case is .gitignore

Creating a remote branch
After creating the branch locally: You can specify a different remote name other than origin

Getting a local tracking branch of a remote branch
Get the remote branch name:

To then get access to stable, do this: or, to give it a different local name:

Pulling all remote branches
After you clone a project, you actually have references to all remote branches:

You should periodically refresh the contents of these remote branches with

If you just want to take a quick peek at an upstream branch, you can check it out directly:

But if you want to work on that branch, you'll need to create a local tracking branch:

Deleting a local branch
If the branch has not been fully merged, you can force it with

Deleting a remote branch
If this doesn't delete your local copy of the remote branch, do this:

Creating a branch retroactively
(from http://stackoverflow.com/questions/364925/is-it-possible-to-retroactively-turn-a-set-of-commits-into-a-branch)

Working with tags
To see existing tags:

To tag a version (can do it retroactively with )

To revert to a tagged version

Undeleting a file
Should do it. If you don't have any uncommitted changes that you care about, then should forcibly reset everything to your last commit. If you do have uncommitted changes, but the first command doesn't work, then save your uncommitted changes with git stash: Source: http://stackoverflow.com/questions/2125710/how-to-revert-a-git-rm-r