GIT Cheat Sheet

GIT Cheat Sheet

I have compiled some basic git commands under “GIT Cheat Sheet”.

The are certain git commands which are used frequently and can help your way while working with a git repository.

GIT Cheat Sheet

Git Help

The git help for the various commands can be accessed via –help.

The syntax is:

git command –help

Some git basic concepts

master	:default development branch
origin	:default upstream repository
HEAD	:current branch
HEAD^	:parent of HEAD
HEAD-4	:the great-great grandparent of HEAD

Create a git repository.

cd /data/for/repository/
git init
git add .

Get the data or checkout via git.

On the same server running git repo-

git clone /data/for/repository /checkout/location/for/data

Clone git repository remotely-

git clone git://git-host.org/git-repo.git
git clone ssh://git-host.org:git-repo.git
git clone [email protected]:git-repo.git

GIT View commands

View file changes in the current working directory.

git status

View changes

git diff

View Changes between certain revision/id

git diff $id1 $id2

View history of changes

git log

View history of changes for file/directory

git log -p $file $directory/$file

View who changed the file along with time

git blame $file

View commit identified by ID

git show $id

View a specific file from a specific ID

git show $id:$file

View all local branches

git branch

GIT Revert Commands

Return to the last committed state

git reset –hard

Note: You cannot undo a hard reset.

Revert the last commit

git revert HEAD

Note: Creates a new commit.

Revert specific commit

git revert $id

Note: Creates a new commit.

Fix the last commit

git commit -a –amend

Checkout the ID version of a file

git checkout $id $file

GIT Branch commands

Switch to ID branch

git checkout $id

Merge branch1 into branch2

git checkout branch2
git merge branch1

Create branch named branch based on the HEAD

git branch branch

Create branch new_branch based on brach some_branch and switch to it.

git checkout -b new_branch some_branch

Delete branch old_branch

git branch -d old_branch

GIT Update commands

Fetch the latest changes from origin

git fetch

Note: The above does not merge the changes

Pull the latest changes from origin

git pull

Note: The above does a fetch and then merges the changes

GIT Publish commands

Commit all the local changes.

git commit -a

Push changes to origin

git push

Make/Mark a version or milestone

git tag v1.0

GIT file operation commands

Add files

git add files

Rename files

git mv old_file new_file

Remove file

git rm files

Stop tracking the file, but keep in the working directory

git rm –cached files

GIT Cheat Sheet

No Comments

Post a Comment

Time limit is exhausted. Please reload CAPTCHA.