Git - frequently used git commands on command line

In this tutorial , we will see some of frequently used git commands which can be run on command line.

I am assuming that git is installed , configured with your credentials and cloned the repository into your local machine.  Now lets see the commands which a developer uses for check in and checkout of code on daily basis.

Create a local branch

git branch new-branch-name

Above command will create a branch locally. Until you checkout this branch and push it, it will not be available remotely.

Show the list of branches

git branch --list // lists all local branches
git branch --list -r // lists all remote branches
git show-branch // lists all local and remote branches

Checkout an existing branch

git checkout existing-branch-name

Above command will switch or restore the branch to given existing branch.

Create and Checkout branch in single command

git checkout -b new-branch-name [existing-branch]

It will create a new branch and base branch will be the given existing branch.

Check the status of branch and file changes

git status

It will show the current branch name and both new and modified file list.

git status command result

Stage the changes

git add filenames-with-changes

Staging of changes means preparing them for commit. Until you stage the changes using this command, same cannot be committed to a branch.

Commit the changes to current branch

git commit -m commit-message

This command would commit the current changes which you have seen through status command to the current branch.

Push the changes to remote repository

git push origin branch-name

Pushes the branch with changes to remote repository.



1 Comment

  1. Hi, very nice website, cheers!
    Need cheap and reliable hosting? Our shared plans start at $10 for an year and VPS plans for $6/Mo.
    Check here:


Submit a Comment

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>