-
Notifications
You must be signed in to change notification settings - Fork 30
Git Workflow
- http://gitimmersion.com/index.html (quick)
- http://git-scm.com/book (long)
This is a (very short) git workflow tutorial as it pertains to this project.
Begin by cloning the project:
git clone https://github.com/amatsukawa/dblog.git
Git is a distributed version control system, meaning the repository that you just cloned is the full repository, capable of functioning on its own. To start a new feature, create a branch
git branch --track my-feature
git checkout my-feature
If you want to check out a remote branch and edit it,
git checkout -b test origin/test
Now, you can edit some files. Once you are ready to commit changes, do
git add file1 file2 # any files you want to commit
git commit -m "message"
This commits to your local repository. You must add files each time you want to commit it (this is called "staging" the files). Since each commit only affects you, it is common practice in git to make frequent, small commits. When you are done with your feature, switch back to the master branch and merge it in.
git rebase master
git checkout master
git merge my-feature
See the guide below for the difference between rebase and merge. This may seem redundant, but it has the advantage of allowing you to resolve any conflicts in your feature branch. The second merge to master is a simple fast-forward.
If you stay on a branch too long, it may get out of date from the master branch. This will make the eventual merge harder. To prevent this, frequently sync with the master branch from your my-feature branch.
git fetch origin master
git rebase origin/master
At any time, you can push to Github to share changes with others.
git push
If you want to sync other people's changes, you can pull.
git pull
It is possible that git will complain that you have uncommitted changes when you pull, because it doesn't know what to do with these files. If the files are ready to commit, simply do so. If you are not ready to commit these changes, you can still pull by using "stash"
git stash
git pull
git stash pop
Stash works as a stack for your changes, you can uncommitted changes to it, pull, and pop the changes back out.