Git Tutorial

git init learngit

This will create a new git repo in the folder named learngit.

We are ready now to use git within our local system.

When we say git init , it creates a directory named .git inside the folder.
This contains the stuff needed by git to work.

If you want to copy existing code base in git to your local system , you have another way.

git clone url_name

Create a new file named readme.txt

Add some content to it

git add readme.txt

This command it telling that i want this file to be considered for saving it git.
When we say this , git stores that to index.

Commit the file

git commit --message "Adding a new file"

This command saves the file which we added to index into the git.

git log

Git log shows the history about what work has been done and by whom

git diff

We can use this command to find difference the two commits

git diff master~1 master

Another similar syntax is
master^1


This will show changes to all the files onto master on current version from previous commit

git diff master~1 master --filename.txt

If you want to see diff only for specific file you can use above command.

git diff

without an argument views the differences between the current
working directory and the index staging area.

git diff master

views the differences between the current working directory and the last commit on the
default master branch


While working with word documents you might want to use the

--word-diff

This shows diff at the word level rather then lines

git diff --word-diff master~1 master --filename.txt

Another format of diff is

--stat

This command shows the summary in terms of line changes + and - , rather than details about changes.


To see what is the sha for given reference (branch or master)
use the following example

git rev-parse master