Useful Git Commands

I've used git quite a bit but I don't consider myself a git expert, per se. I often find myself looking up the same basic commands so I thought I'd share them there so I'd have a fast reference, and maybe this will help you out too!

Create and Checkout a New Branch

#branches from currently checked out directory git checkout -b <branchName>

Checkout a Remote Branch

git checkout -b <localBranchName> origin/<remoteBranchName>

Abort Changes of a File

git checkout -- <fileName>

Modify the Previous Commit's Message

git commit --amend

Partial Change Checkin

git add --edit

Undo the Previous Commit

git revert HEAD^

Temporarily Stash Changes, Restore Later

# After changes have been made... git stash # Do some other stuff here, like switch branches, merge other changes, etc. #Re-apply the changes git stash pop

Delete a Remote Branch

git push origin :<branchName>

Pull in the Latest from a Shared Repository

# Add a remote branch git remote add <remoteName> <gitAddress> # For example: git remote add lightfaceOfficial git://github.com/darkwing/LightFace.git # Get changes from that branch git fetch <remoteName>

Tagging, Deleting, and Pushing Tags

# Create a Tag git tag <tagName> # Delete the tag git tag -d <tagName> # Push Tags git push --tags

Who F'd it All Up?

git blame <fileName>

These basic git commands should help you on your way. Have a tip you'd like to share with others? Please share!