Category Archives: Git

Quick Guide For Git Commands

Here is a list of commands which help you to work with git.

Setup Git
Type following in Git Bash to setup git

Sets the default name for git to use when you commit:
$ git config --global "Your Name Here"

Sets the email id used when committing code:
$ git config --global ""

How to initialize git in a folder
In git bash, navigate to project folder using cd command. Then type following command:
$ git init

Create a file in git folder
Navigate to project folder(git folder) and type:
$ touch<file_name>

Add a file to the list of files to be committed
$ git add<file_name>

Commit changes in local repository(in our machine itself)
Taking a commit means taking a snapshot of current project. The changes are not reflected in main github server now.
$ git commit -m 'first commit'
-m is for message. Here a message “first commit” is added to commit

Push your commit
Pushing our local commits to github server is done first by setting a remote to github repo
$ git remote add origin
This is a one time action as remote name is created here

Here the remote name is “origin” pointing to repo. Now the master folder is pushed to “origin” using following command
$ git push origin master
Forking a repo
Its done to work on others projects or to start from others work. First move to new project folder and clone the forked repo
$ git clone
This will copy the files and folders to project folder

Adding all files inside git folder to repo
git add *

Creating a Branch
git branch branchname

Select a branch
git checkout branchname

Switching between branches
git checkout master git checkout branchname

Merge a branch
git merge branchname

Delete a branch
git branch -d branchname


Posted by on September 13, 2013 in Git