Geeks With Blogs
Sathya Narayanan Srinivasan .NET Developer

Concept of git 

In a git project, there will be two branches for each branch that you have :
one is local branch and other is remote branch
you always commit to your local branch and 
when you push the changes will get updated in the remote branch.
(if we dont do a push, the other person working in same project/branch will not get the changes at all)
if the other person in same project/branch needs to get the changes, then he/she has to do a git pull or git pull --rebase from the remote branch.

git commands that will be used in order 


git clone "git url" - creates new repo
git fetch origin - bring all remote branches
git checkout <branchname> - checks out the branch that you need
git branch - checks which branch ur in
git status -s : lists what are the pending changes
git pull orign <branchname> - first time
git add "filename"
git commit -m "Message"
git pull --rebase origin <branchname> - make sure that ur branch is up to date - updated from the remote

This is for getting all changes in master 

git pull --rebase origin master -- this is to bring all changes from your master branch
git pull --rebase origin <branchname> -- this is to bring all changes from your master branch

if conflict exists, see whats the conflict and resolve them 

git status -s : it will list all changes
look for "UU" - this means, the files with UU status has conflicts
open those files 
look for "<<<<" or ">>>>" or "===="
make necessary changes in the file and save it
git add "filename"
git status -s : check if the UU has changed to "M" or some other meaningful status
git rebase --continue - this will continue the rebase operation
If you get some message like "Nothing to continue"
git add -A -this will add all the files that are modified/added
git rebase --continue - this will continue the rebase operation
if you still get the above error
git rebase --skip
finally after going thru this rebase and conflict fix loop
if you do
git rebase --continue
you will see the message "No rebase in progress?"
it means you dont have any pending rebase
git branch - this will show you ur current branch. if the rebase did not succeed, you will see *(nobranch)
in case you want to abort your rebase operation:
git rebase --abort

git push origin <branchname> - this pushes your changes to ur remote branch


To merge to master 

git checkout master
git pull --rebase origin master
git merge <branchname>
if conflict exists, resolve them (same procedure as above)
git push origin master


for creating a new branch off ur current branch 

git checkout -b <newbranchname> 

Posted on Thursday, June 26, 2014 7:03 AM git | Back to top

Comments on this post: Useful git instructions / commands

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © sathya | Powered by: