After successful Installation:

where is the git located

  • ~$ which git
  • /usr/bin/git

the version of the git installed

  • ~$ git --version
  • git version 1.8.3.4 (Apple Git-47)

Configuration:

System wide git configuration file path: /etc/gitconfig
User git configuration file path: ~/.gitconfig
Project git configuration file path: PROJECT/.git/config

set user name (User configuration)

  • ~$ git config --global user.name "YOUR USER NAME"
  • [--global indicates User configuration]

set user email id (User configuration)

  • ~$ git config --global user.email "YOUR EMAIL ID"

set default text editor for git

  • ~$ git --version
  • git version 1.8.3.4 (Apple Git-47)
  • ~$ git config --global core.editor "textedit -wl1"
  • [-w indicates, git should wait for next task until editor is closed]
  • [l1 indicates, the text editor will put the cursor at line 1 when starts]

use colors with git command line

  • ~$ git config --global color.ui true

Current status of configuration

Auto Completion for Git:

Windows already have Auto completion feature already. So the instruction are for Mac and Unix user only

Download the completion file form

  • ~$ git config --global color.ui true

Github

  • ~$ cd ~
  • ~$ curl -0L https://github.com/git/git/raw/master/contrib/completion/git-completion.bash

Rename file

  • ~$ mv ~/git-completion.bash ~/.git-completion.bash

Open bash profile file

  • ~$ nano .bash_profile

Edit bash profile file
add this code to the file

  • if [ -f ~/.git-completion.bash ]; then
  • source ~/.git-completion.bash
  • fi
  • now hit: ctrl + x to close the file
    now hit: y to say, yes I want to save the file
    now hit: enter to go back
    restart terminal (quit and open again)

Git Help:

Open git help

  • ~$ git help

Open git help for specific command

  • ~$ git help log
  • hit f to move forward
    hit b to move backward

Starting Git

Initialize a project
Select a folder where you would like to create a project (that will be tracked by Git)
On terminal go to that folder (write cd and drag drop the folder)

  • ~$ git init
  • Initialized empty Git repository in
  • /Users/Documents/Sourcecode/Git/first_git_project/.git/

Add files to Git
Create your first file inside the directory

  • ~$ git add .
  • [. indicates that all files inside the directory should be added to Git]

First commit with Git

  • ~$ git commit -m "Initial commit"
  • [master (root-commit) d68b938] Initial commit
  •  1 file changed, 1 insertion(+)
  • create mode 100644 first.txt
  • [-m indicates that we are going to add a message next]

Few tips on commit messages

  • write commit messages is present tense, not past tense.
  • write “fix bug” or “fixes bug”, not “fixed bug”
  • you can add bullet points using asterisks for hyphen
  • Its a good idea to add ticket tracking numbers/ bug report number with commit
  • Be clear and descriptive
  • for example, Bad: “Fix typo”, Good: “Add missing > in project section of HTML”
  • Bad: “Update login info”, Good: “Change user authentication to Blowfish”

A good commit message example

t23094 – Fixes bug in admin logout

When an admin logged out of the admin area, they could not log in to the members area because their session[:user_id] was still set to the admin ID. This patch fixes the bug by setting session[:user_id] to nil when any user logs out of any area.

Git Log

View the last commits

  • ~$ git log
  • [. indicates that all files inside the directory should be added to Git]

View the last commits up to limited number

  • ~$ git log -n 1
  • [-n 1 indicates, it will show the last 1 commit]

View the last commits since up to a date

  • ~$ git log --since=2013-12-09

View the last commits until a date

  • ~$ git log --until=2013-12-10

View the commits of a particular author

  • ~$ git log --author="shahab.uddin"

View the commits with a regular expression

  • ~$ git log --grep="Init"