GIT Tutorial Part 1:

Git Tutorials:

Git is the distributed version control system unlike SVN, which is client server based system. In Ubuntu and Debian install GIT with apt-get install git.

1.    Initialise the GIT repository:

$ mkdir gitrepo

$ cd gitrepo

$ git init

This will create a directory named .git where all indexes are stored required for the git. This directory is used to track all the files in the repository. It contains various file, only you may need a file  .config.

2.    Performing your First Commit:

$ git add <file name> or to add all the files in the repository, git add .

$ git commit –m “ Message for the commit”

Always remember the 3 cycles:

Basic Cycle:

  • Make changes
  • Add the changes
  • Commit the changes to the repository with a message.

3.    Commit Messages:

Present Tense not past tense

Short single line

 4.    Viewing the Commit Log

$ git log

Commit no, Author and Date:

Each commit has unique ID called SHA1

$ To view help git help log

git log –n 1

git log  –since=2012-06-15

git log –author=”daya”

git log –grep=”Init”

5.    Referring to Commits

  • GIT refers to each commit by a unique number called SHA1, i. e a change set is represented by checksum.
  • When we submit each change to the GIT repository, git will generates a checksum for each change set.
  • Applying checksum algorithm in the data generates simple number.
  • Same data always have same checksum values.
  • In git data integrity is fundamental changing data would change checksum.
  • Git uses SHA1 algorithm to create checksum.  ( 40 character Hex String).

6.    Making changes to file:

git status shows the difference between working directory, staging index and the repository.

Macs-MacBook-Pro:gitrepo daya$ git status

# On branch master

# Untracked files:

#   (use “git add <file>…” to include in what will be committed)




nothing added to commit but untracked files present (use “git add” to track)

Macs-MacBook-Pro:gitrepo daya$ git add

Macs-MacBook-Pro:gitrepo daya$ git status

# On branch master

# Changes to be committed:

#   (use “git reset HEAD <file>…” to unstage)


#                                       new file:


# Untracked files:

#   (use “git add <file>…” to include in what will be committed)



(Here one file in staging index and one file in working index)

Macs-MacBook-Pro:gitrepo daya$ git commit -m  “Added the repo file”

[master 2969cc4] Added the repo file

1 file changed, 2 insertions(+)

create mode 100644

                                                      git commit –m “message”

Will commit the files in staging index.

7.    Editing Files:

Macs-MacBook-Pro:gitrepo daya$ git status

# On branch master

# Changes not staged for commit:

#   (use “git add <file>…” to update what will be committed)

#   (use “git checkout — <file>…” to discard changes in working directory)


#                                       modified:


git add (added in the staging index)

git commit –m “ Modified the repo, with apt-get

8.    Viewing changes with diff:

git diff or git diff filename