Most Common Git Commands

git branch -b new_feature
git branch –no-merged # show the branches that are not merged yet.
git merge –no-ff new-feature -m “merge new-feature branch”
git branch -D new-feature # delete the working branch after merge is completed


Working with GitHub

create a GitHub repo hello-remote

git clone <URL for hello-remote>
git clone
git status

add a demo file in local clone, demo.txt

git add demo.txt
git commit -m “added a demo file”

git push -u origin master # now upload the file to the GitHub.

git fetch origin # use this to update the local clone of the remote repository. This let us know how many commits have been made since the last pull
git remote -v # shows the branch on the remote location.

git pull # use this command to update the local repo. (Behind the scenes, git pull is actually a git fetch followed by a git merge)

Coll flag for git diff:

git diff –color-words

Try this feature.
git branch –merged : shows all of the branches that are merged.

Take a look at the diff between branches:
git diff master..branch_name

Rename a branch in Git
git branch -m old_branch_name new_branch_name
git branch –move old_branch_name new_branch_name

Delete Branches
git branch -d branch_name
git branch –delete branch_name

if there are changes in the branch that is not merged yet, we must use D
git branch -D branch_name # forced delete


Viewing Git Logs

Some common git log comments that I use heavily.

# view git logs
git log

#limit number of logs to show
git log -n 1 # last commit
git log -n 5 # last 5 commits
git log –since=2017-06-01
git log –until=2017-06-01

git log –author=”Ankan Basu”

git log –grep=”init” # look for changes in the commit message
git log –grep=”bug” # log for commit messages with bug fixes.


git log –oneline

git log –format=oneline

git log –graph

git log –oneline –graph –all –decorate


Sample initial git set up commands

This is a sample initial git set up commands I use for my projects.

git config –system
git config –global
git config # this is for project basis configuration.


#Configure initial set up
git config –global “Ankan Basu”
git config –global “”

# check configuration
git config –list

# set up the default text editor for git
git config –global core.editor “vim”

# use colors with git
git config –global color.ui true