Home > technology > Useful Git Commands

Useful Git Commands

As our project migrated from SVN to GIT repository, I thought of writing a post of the usual git commands which I find helpful where I could easily refer to.

**Set up Local Repository

#clone a repository into a new directory locally

git clone <SSH key>

#checkout a branch or path to the working tree

git checkout <branch name>

**Working with Branches

#display all the available branches in your local, highlighting the active branch

git branch

#download all/new branches

git fetch

#switch working branch

git checkout <branch name>

#create new branch locally

git checkout -b <branch name>

#push newly created branch to remote

git push -u origin <branch name>

**Committing Local Changes to remote

#show staged files for commit, not staged files for commit and untracked files.

git status

#include what will be committed, stage the changes

git add <file>

#discard changes

git checkout — <file>

#to add message for commit

git commit -m “message here”

#take latest commits on the mentioned branch

git pull origin <branch name>

#push local changes to the remote

git push origin <branch name>

Advertisements
Categories: technology Tags:
  1. No comments yet.
  1. No trackbacks yet.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: