Last modified 5 years ago Last modified on 05/22/14 15:36:18



sudo apt-get install git gitk

Config your personal information:

# To set it globally for all repos
git config --global "Firstname Lastname"
git config --global ""

# To work with different repos
cd my_other_repo
git config "Different Name"
git config ""

Clone a repo (first fork the project from the site if needed):

git clone                # From github
git clone   # From bitbucket
git checkout develop                                                   # Change to branch develop (and develop there)

An example of clone, remote, branch, fetch, merge.

git clone
git remote add upstream
git checkout develop
git fetch upstream
git merge upstream/develop


git add file             # Adds file to the files to be commited
git commit -m"msg"       # Commits to local repo
git push                 # Push all commits since last push to your repository, hosted in a server

After you've made some changes (e.g. fixed a ticket) make a Pull Request in the site.

Merging sources from your upstream repository (make sure to push changes to your repository first):

git remote add upstream remote_repository  # Set upstream to remote_repository (e.g.,
git fetch upstream                         # Get all files from upstream
git merge upstream/develop                 # Merge all changes. If there are any conflicts, you'll have fix them manually and execute this command again.
git branch -lv             # Show branches with verbose option
git remote -v              # Show remotes with verbose option
git remote -rm this_remote # Remove this_remote

Additional Help:

Advanced Git Configuration

Put this in your .gitconfig

	email =
	name = Your Name

        st = status
        ci = commit
        br = branch
        co = checkout
        df = diff
        # Pretty log with branch
        lg = log --color --graph --pretty=format:'%h %C(blue)(%cr) %C(bold blue)<%an>%C(reset)%C(red)%d%C(reset) %s' --abbrev-commit --
[color "branch"]
        current = green bold
        local = yellow bold
        remote = red bold

[color "diff"]
        meta = blue bold
        frag = magenta bold
        old = red bold
        new = green bold
        whitespace = red reverse

[color "status"]
        added = yellow bold
        changed = green bold
        untracked = red bold

        ui = true

Tips and Tricks

Really Blame It

git blame -C

More Specific Blaming

Let's say the piece of text you are investigating is this:

a = get_something(some_var)

and it is located in the file some_folder/

Then, try this command:

git log -S "a = get_something(some_var)" some_folder/

Then, GIT will look for the string we specified within the commit history and output something like this:

commit <a commit hash>
Author: Some Dude <>
Date:   Fri Feb 15 14:09:18 2013 -0300
    The commit message of this commit.

Individually review and stage changes within each file

git add --interactive

Diff after add

git diff --cached