Dreamsys Web & software Blogs

Single Blog

Git Cheat Sheet for newbie and beginners

In today’s world,
Collaboration with team members without Version Control Tools are miserable.
 Among Version Control(VC),Git is one of effective and productive tools for every developers,designers,analyst,tester,product manager or any stake holder.
And best part is Using git you doesn't need much more effort in learning and adapting.
Just ¾ command and you are ready to go,collaborating with your team members.
So I will be providing git common cheat sheet so that even newbie can kick off their project with awesome version tool.

CONFIGURE GIT

Command

Usage

$ git config - - global user.name “[name]”

Sets your username for the git repo/commit globally

$ git config - -  global  user.email “[email address]”

Sets your email for the git repo/commit globally

 

 

 

 

CREATE REPOSITORIES

$ git init [project-name]

Initialize git repository to start tracking.
[project-name] is optional.

$ git clone [url]

 

Download a project and entire version history to get start with.
You will need to do cd [project name] to enter to project

MAKE CHANGES

$ git add [file]

Stages[add to track list] the file,ready to commit

$ git add .

Stages[add to track list] all changed file,ready to commit

$ git commit -m “commit message”

Commit all the staged file on the version history

$ git reset [file]

Unstages the file,but preserve its contents

BRANCHES AND TAGS

$ git branch

List all local branches

$ git branch -av

List all local branches plus remote branches

$ git branch [branch-name]

Creates a new branch

$ git checkout [branch-name]

Switches to specified branch and updates working directory

$ git checkout -b [branch-name]

Switches to new branch with all changes of current branch

$ git branch -d [branch-name]

Delete the specified branch

$ git merge [branch-name]

Merge the branch of [branch-name] with current branch

$ git tag [tag-name]

Tag the current commit.
It is very useful for versioning

SYNCHRONIZE CHANGES

$ git push [remote] [branch]

Push all the changes of local branch to alias/remote.[ie origin by default].
Shortcut will be
$ git push

$ git pull [remote] [branch]

Pull the branch in to current directory of specified remote.

$ git fetch

Get lastest changes from origin with no merge

REVIEW HISTORY

$ git status

List all new/modified files under that

project

$ git log

List version history for current branch

$ git diff [branch1] [branch2]

Show changes between two branch

$ git diff [commit1] [ commit2]

Show changes between two commits

$ git show [commit]

Outputs meta data and content changes  of specified commit

UNDO{LIFE SAVER}

$ git reset - -hard HEAD

Discard all local changes in your working directory

$ git reset - -hard [commit] 

Discards all history and changes back to the specified commit

$ git remote set-url [branch-name] [url to branch]

Changing the url of the remote branch