7/24/15

Most Used Git Commands

Useful Git commands 






To Check branches
> git branch

Getting a branch without pulling code
> git fetch

Clone a repository
> git clone <repo url>

Create a new branch
> git checkout -b <branch name>

Commit code
> git commit -m "your message  for this commit"

Push code to a branch
> git push origin <branch name>

Get updated code from master branch
> git pull

Get updated code from some branch
> git pull origin <branch name>

Check Files Required to commit or changes made
> git status

Add a file to index
> git add <file name>

Add all files to index
> git add .

Check last few commits in chronological(latest first) order
> git log

Create a new local repository
> git init

Switch branch
> git checkout <branch name>

Connect Local repository to remote
> git remote add origin <server url>

Update remote origin URL
> git remote set-url origin git://new.url.here

Merge other branch to your branch
> git merge <other branch>

Locally save your changes and set your local working directory to HEAD (last commit)
> git stash

Apply locally saved changes
> git stash apply

Merge branch b1 to b2 : current branch is b1
> git merge b2

Remove File from git add
> git reset <file>

Check all branches present at remote site
> git branch -r

Delete local branch
> git branch -D <local branch name>

Get first git commit
> git log --pretty=format:%H | tail -1


This list gives you most frequent used git commands.