+91 9790664230
kumar.arun211@gmail.com

git commands cheat sheet

Blog to learn python and selenium

git commands cheat sheet

It is hard to memorize all the important Git commands. We’ve included the basic Git commands; Use this handy git cheat sheet to enhance your workflow and save your time. We recommend you to print this out or save it to your desktop to resort to when you get stuck.

Clone an existing repository

git clone git@github.com:username/.git

Note: By default, master branch is checked out

List changes in your working local directory

git status

Show current changes to tracked files in local directory

git diff

Show current changes to a particular tracked file in local directory

git diff <file-path>

Add all files with changes to next commit

git add .

Add specific file with changes to next commit

git add <file-path>

Commit previously staged changes

git commit

Commit previously staged changes with commit message

git commit -m “commit message”

Display all commits details (Last commit first)

git log

Display all commit details to a specific file

git log -p <file-path>

List all existing branches in local repository

git branch

List all existing branches in local repository with latest commit message

git branch -v

List all existing branches in local as well as remote repository

git branch -a

List all existing branches in local as well as remote repository with latest commit message

git branch -av

Checkout a branch from remote repository (HEAD automatically switched to newly checked out branch)

git checkout <branch-name>

Switch to one local branch to another local branch. (if branch not available in local, same as previous command)

git checkout <branch-name>

Create a new branch from current branch or HEAD (switches to newly created branch automatically)

git checkout -b <branch-name>

Delete a local branch

git branch -d <branch-name>

Checkout changes from remote-tracking branch of current HEAD and merge

git pull

Checkout changes from specific remote-tracking branch and merge it to current HEAD

git pull <remote-name> <branch-name>

Note: Default remote name is ‘origin’

Push changes to remote-tracking branch of current HEAD

git push

Push changes to specific remote-tracking branch from current HEAD

git push <remote-name> <branch-name>

Renaming a Branch

git branch -m <old-branch-name> <new-branch-name>

Note:

  • Push operation has dependency on commit operation which means if there are no commits in current branch, push command does nothing
  • Default remote name is ‘origin’

Checkout changes from remote-tracking branch without merging it into current HEAD

git fetch <branch-name>

Note: Default remote name is ‘origin’

Merge a branch to your current HEAD

git merge <branch-name>

These are all some basics commands that helps you to start with. Happy coding!!!

 

Leave a Reply

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

© 2018 Copyrights. All Rights Reserved. Arunkumar Velusamy