By | May 4, 2018


Distributed Version Control System?



Software Developers, Testers, Business Analyst to maintain Business Docs, Technical Writers.

Collaboration Issue Solve by VCS(Version

Control System)

If You need to Change a File from a server so you need to pull down the file from the server, make changes locally and then update on server , if two or more developer is making changes on same file and update the file on server , then there is Collaboration Issue  will come.

Client vs Server Machine

To Solve this Collaboration Issue we Need Source Control System or Version Control System.


A Version Control System

If two different developer working on the same file so it merge the changes into a single file. It also maintain the timeline or time log of changes happens during development.


Central Repository v/s Distributed Repository

Network Connection

Git is Distributed Repository, It Means it maintain a Local Repository for every developer to maintain their changes locally and then merge to the centralized place.

The Best Part is if the centralized Repository is down you can use your local repository for work.


Linus Torvalds Invented Git



Git is a Version Control System , It is Command Line.

GitHub is a WebSite , You can say a Web Version of Git.

For Using GitHub , just create a account on GitHub and then create a Repository there.

Create a New File from there. Commit (Save) a New File.

You can see the History of Changes.

Git create a master branch , whatever you commit it will store in master branch.

Branch- Create a sub branches of master just for experimental purpose ,once it is done then merge to the master branch.

You can Pull and Merge Request

You can Fork and Pull Request

Fork v/s clone

Fork is just copy of certain workflow of Git, where clone is complete copy of repository.

You can Create Issues, Resolving And Close Issues


Git Command Line

Install Git


Once git command line Install and Path is set type git —version // to check the git version



git help —> to check the commands available on git

to check specific command type git help config or git help add

git help <command name>

NOTE :To Get out from any command help press Ctrl + Z to exit from Git Help

Setting Up Git

git config —global user.name amitsrivastava4all git config —global user.email


git config —global color.ui true     // For Command Line Colors

Start using GIT Create a Folder mkdir <foldername>

cd <foldername>

git init  // this will create a local Repository and it has .git hidden directory in the current folder create hello.txt

git status // to check the status where we are then add it into staging area

Adding file it into staging area so the file is ready to commit on Local Repository.

git add <FileName> or git add —all or git add *.extension or git add <foldername>/*.extension or git add <foldername>/   // will add folder , sub folders and files

or git add “*.txt” // will add all the txt files from the entire project


git add . // add the current directory , sub and files

git commit -m <Change Message> Now make changes in a hello.txt

Add and Commit in One Command git commit -a -m ‘Messageʼ Check Status git status

Now git add <FileName> git commit -m <Change Message>

Now to Check History

git log

git diff // show unstage difference with the last commit

git diff HEAD // same as git diff git diff HEAD^  // parent of the latest commit

git diff HEAD^^  // grand parent of the latest commit

git diff HEAD~5  // five commits ago

To Discard the Changes from the HEAD (UNSTAGE FILE)

The HEAD is a Pointer on Last Commit on Time Line.

git reset HEAD <FileName>

git status git diff

git checkout <Filename> // Discard the HEAD Changes and move back to master Head. git status git diff

Undo the Last Commit

git reset —soft HEAD^   // Undo the Last Commit and Now file on Unstage area git log git status git diff

Undo the Last Commit All remove all changes so nothing is left on Unstage Area. git reset —hard HEAD^   HEAD~1

Undo the Last 2 Commits git reset —hard HEAD^^

Adding the Changes to the last committed git commit —amend -m <Message>

Push the Changes to the GIT

Create Account on GITHUB

Create Repository on GITHUB

https://github.com/amitsrivastava4                all/tester

Add a Remote

git remote add origin https://github.com/ amitsrivastava4all/tester add – adding a repository origin – name for the remote git hub repository url


git remote -v // to show remote repository


git remote rm <remoteName> e.g git remote rm origin

Pushing the Changes to GITHUB git push -u origin master

-u for login origin name of remote and master for local Pull down the latest changes done by other developers on Git

git pull or git fetch

Clone the Repository

git clone <githuburl>  // Clone the GitHub repository and put locally and give a name origin for remote and

give a name master to local, and point to the HEAD.

git remote -v

Create a branch git branch <MyBranchName> e.g git branch example2

To check current active branch git branch

Switch to Branch git checkout <branch name>

Or Create and Switch in one Command git checkout -b <branchname>

Add a new file

git status // check in which branch it added git add <filename>

git commit -m <Message>

Merge the Changes to the Master Branch

i. git checkout master    // go to master branch j. git merge <branchname>

e.g git merge testing

so testing branch get merge to master branch

after merge delete the branch you have created git branch -d testing  git branch -d <branchname>


CASE – I  (Merge Commits)

Amit Push Changes to GitHub

Ram want a clone of Amit repository

Ram Do ——>  git clone <URL of the Amit


After Clone Ram add two new files git add —all

git commit -m ‘Ram changesʼ

Same Time amit is doing the changes on some other not Ram files and push the changes to git

Amit ——> git add —all

git commit -m ‘Amit Changesʼ git push

If ram try to push now git push —> Generate error

So ram will do —> git pull or git fetch then git push

CASE – 2 (Conflicts)

Amit and Ram working on same file test.txt Ram commit the changes and push the changes to the git

Amit just commit the changes locally Now amit need to pull the changes

Now this time error is coming it says Merge Conflicts it pull down the changes from the git and try to merge it with Amit changes locally so it fail. So we need to do the merging manually on Amit Local .

And then commit the changes and Push the changes by Amit


git checkout -b <branchName> —> this will create the local branch

Making changes in Local branch git add —all git commit -m <Message>

git push origin <branchName> —> Links Local branch to the remote branch

git branch —> to see all local branches git branch -r —> to see all remote branches

Removing a Remote Branch git push origin :<remotebranchName>

Then Remove Local Branch git branch -d <LocalBranch>

Tag – It is used for Version Maintain , It is usually use for release versioning git tag —> to list all tags

To add a tag

git tag -a V0.0.1 -m ‘Version 0.0.1 Addedʼ

git push —tags

REBASE v/s MERGE commits

In the case – I and Case-2 the Merge Commit will pollute the Commit History

So if we want to maintain the step by step history of commits we use Rebase

git rebase

  1. Move all changes to master which are not in origin/master to a temporary area.
  2. Run all origin/master commits
  3. Run all the commits in temporary area on Master on at a time. git checkout admin git rebase master git checkout master git merge

In case of conflicts

Case – If two developer modify the same file git fetch

git rebase git status

git add test.txt git rebase —continue

Git History git blame index.html —date short

git stash git issue git fork


Leave a Reply

Your email address will not be published. Required fields are marked *