Thursday, February 2, 2012

How to use Git to test an idea

Setup git in your project directory:
git init
This will create a local .git repository for git. Run
git status
As we did not add any files to git, it will show you all files as untracked.
Suppose we want to exclude .svn folders from git, then in .git/info/exclude, add line
.svn*
From now on, git status won't show .svn folders anymore.
Add all project's files to git:
git add .
git status will show all files as ready to be commited. Proceed:
git commit -am "initial file import"
Run: git status - it will show everything is ok
Now, suppose we want to experiment a new idea without impacting other developers. For that, we will create a new branch.
git branch idea
git checkout idea
or
git checkout -b idea
Run git status, it will show you are in new branch.
Now you can make all you changes and commits.
If you want to switch back to the main branch:
git checkout master
and return to the new branch:
git checkout idea
If you want to merge the new branch into the master branch, you have to move all changes made in the idea branch.
git checkout master
git merge idea
To drop the idea branch, run:
git branch -d idea