Common Git commands

24 Jun

In my previous post last month I described the migration from SVN to Git. Since then I have been using it in my project. This post is about the typical workflow and how it can be achieved in Git.

1. Getting code

mkdir <dirname>
git init
git pull <repo URL>

This will pull the remote repository on your machine. The URL can be HTTP/HTTPS or SSH. In case of SSH you will need to generate a key pair first.

2. Seeing what has changed

git status

Shows the current branch you are on and the staged and unstaged changes.

3. Committing Changes

git commit -a -m <commit message>

Commits all the staged changes.

4. Pushing commits

git push

Push all commits to the remote repository

5. Storing current changes and going back to HEAD

git stash save <stash name>

All current changes are stashed away in a temporary area and resets the current branch

6. Restoring previously stored changes

git stash apply <stash name>

Merges the stashed changes back into the working copy

7. Create a new branch

git branch <branch name>

8. Switch to another branch

git checkout <branch name>

9. Merge branch with master

git checkout master
git merge <branch to merge>

10. Cherry pick changes from another branch

git cherry-pick -e -x <commit>

Pick specific commits, maybe from another branch, and apply to working copy

11. Tagging

git tag <tag name>

If you are new to Git you will find the Git GUI to be very handy. However, it does not support all the git commands such as stash. I always end up using both the command line and GUI at times when I get a bit lazy.

Leave a comment

Posted by on June 24, 2011 in Git


Leave a Reply

Fill in your details below or click an icon to log in: Logo

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

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

%d bloggers like this: