This post shares some useful commands which are used commonly.

Configuration

For making some configuration level changes following command is used

git config --// parameters check using --help

Creation

It include commands by which you create a repository or want to use already created

Init

It is used to create git repository in some directory. Execute following command in directory.

git init

Clone

It is used to download a repository source code from remote into your local. For this following command is used.

git clone

Change Management

Status

If you want to see changes done on source code. It shows both type of files index and non-indexed. Indexed files are basically those which are under version control. For this following command is used.

git status

Add

If you want to commit your file, first you have to add them or stage them. For this following command is used.

git add * // to add all in one go git add < file or directory>

Commit

When you want to commit changes to local repository. For this following command is used.

git commit -m "Commit Message" // it will just commit
git commit -a -m "Commit Message" // it will perform add then commit -a will add only tracked files

Diff

When you want to see changes or difference you have from repository code which is basically known as HEAD. For this following command is used.

git diff // diff with HEAD
git diff  // diff with specific only

Branch Handling

List of branches

When you want to see all branches following command is used.

git branch
git branch -a // will show remote branches also

Checkout a branch

It is used when you want to move to another branch or creating new branch from current.

Note : First you have commit your changes on existing branch or stash them.

git checkout 
git checkout -b

Merge two branches

It is used when you want to combine source code of two branches or committed code. For this following command is used.

git merge <Branch Name>

Branch Delete

It is used when you want to delete a branch from local and remote.

git branch <Branch Name>
git branch -D <Branch Name

Code Synchronization

Fetch

When you want to get all information from remote to your local such as new branches and changes.

git fetch

Pull

When you want to get latest changes from remote following command is used.

git pull

Push

When you want to push your changes to remote

git push

Advance Level Commands

Cherry Pick

It is used when you want to integrate change of a particular commit into your current commit.

git cherry-pick

Rebase

This will revert all commits since the current branch diverged from upstream, and then re-applies them one-by-one on top of changes from the HEAD of upstream.

git rebase <upstream>

Clean Up Commands

Remove & Moving of File

git rm <file>
git mv <file>

Reset

git reset
git reset remote | branch

Clean

It remove files which are not on version control.

git clean

Thanks!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s