Skip to content

Git and GitHub usage

f0t0n edited this page Mar 6, 2013 · 1 revision

The current production branch is master.
Each feature / fix should be created in separated branch.

So you are starting new feature / fix.
First of all you have to update your master

git checkout master

git pull origin master

Then let's create new branch

git checkout -b bug-user-login

git push origin bug-user-login

bug-user-login is example. First word should be bug or feature and then description. New branch has been created and pushed to GitHub.

Then you work with your code locally, make changes, commits etc. Issue is solved and you have to push your code to github

git push origin bug-user-login

Okay, it is pushed. Now you have to rebase from master and then create pull request

git checkout master

git pull origin master

git checkout bug-user-login

git rebase master

git push -f origin bug-user-login

Perfect! Just now you switched to master, update it, then switched back to bug-user-login and rebased changes from master to your branch. Now you have clear history, cool!

Now that your bug branch is rebased you should run some tests on your branch to make sure something didn't break.

And now go to your branch in github and click Pull request button. The request will be reviewed and merged to master by someone.

Once peer-review is done you should rebase again. Sometimes other branches have been merged into master and your master branch is now out of date. If you merge your changes you could overwrite other peoples hard work. Before you merge into master please test your rebased branch again. You never know when things might break.

Never click "merge pull request" on github.

Merge branch after code review:

git checkout master

git pull origin master

git merge --no-ff bug-user-login

git push origin master

Maybe some changes has been applied to master by other contributors during your waiting for code review, therefore if git pull origin master shows some updates in master, you have to rebase your branch before merge.

And delete it after merge and code review

git push origin :bug-user-login

git branch -d bug-user-login


Note: Same flow is applicable for work on master's sub-branches or sub-sub-branches, etc.

Clone this wiki locally