Everyday GIT Commands

May 22nd, 2012 by Laeeq | 3 comments

We often use GIT  but not regular that’s why its hard to remember all GIT  commands. I also find myself looking up the some basic commands so I thought I had few to share with you. Hope these will be helpful for you.

Create and Checkout a New Branch
  1. #branches from currently checked out directory
  2. git checkout -b <branchName>

Checkout a Remote Branch
  1. git checkout -b <localBranchName> origin/<remoteBranchName>

Abort Changes of a File
  1. git checkout – <fileName>

Modify the Previous Commit’s Message
  1. git commit –amend

Partial Change Checkin
  1. git add –edit

Undo the Previous Commit
  1. git revert HEAD^

Temporarily Stash Changes, Restore Later
  1. # After changes have been made…
  2. git stash
  3. # Do some other stuff here, like switch branches, merge other changes, etc.
  4. #Re-apply the changes
  5. git stash pop

Delete a Remote Branch
  1. git push origin :<branchName>

Pull in the Latest from a Shared Repository
  1. # Add a remote branch
  2. git remote add <remoteName> <gitAddress>
  3. # Get changes from that branch
  4. git fetch <remoteName>

Tagging, Deleting, and Pushing Tags
  1. # Create a Tag
  2. git tag <tagName>
  3. # Delete the tag
  4. git tag -d <tagName>
  5. # Push Tags
  6. git push –tags

Hope these basic git commands should help you on your way.

You can subscribe to PHPZAG.COM posts by Email

 

Related Topics:

 

 

  1. June 2nd, 2012 at 01:15 | #1

    useful article dude,
    Some of them like removing remote branch and tags was very useful for me,

    Thank You :)

  2. June 4th, 2012 at 23:19 | #2

    wonderful put up, very informative. I ponder why the other specialists of this sector don’t realize this. You must proceed your writing. I am confident, you have a great readers’ base already!

  3. June 13th, 2012 at 17:54 | #3

    This blog has inspired me to continue focusing on my own blog

  1. No trackbacks yet.