Main branch for work is master
, but we shouldnt' commit directly there. Some projects can have other branch for develop but futher we assuming that master
branch is for develop.
Release branch is release
. There we prepare code to submit to staging or so. Also in this branch we can create tagged commits.
Feature branches are started with feature/
or fix/
or whatever you want.
git clone <url>
git checkout master
- in case of other active branch switch to mastergit pull --rebase origin master
- refresh local master branch with remote with key--rebase
to avoid of unnessecary commits like amerge xxxx/master with master
git checkout -b feature/my-feature
- create branch and switch to it- updating the code
git add -A
- add to index all edited filesgit commit -m "feat(main): add main page"
- commit changes according to name standardsgit push origin +feature/my-feature
- push commits to remote
repeat items 2-4 if needed. after that push changes again but without +
sign, as we have already that branch remotely.
+
sign is a shorthand for a --force
or -f
parameter. If you made history re-write (rebase
or commit --amend
) you should use forsed push. Make sure that nobody pulled you branch before forced push.
NEVER EVER EVER force push into master branch
TRY DO NOT COMMIT DIRECTLY INTO MASTER
sure IRL we could. :)
Before next steps commit or stash all your changes
git checkout master
git pull --rebase origin master
git checkout feature/my-feature
git rebase master
Now we have updated own feature branch with all changes from master
branch
To avoid history from commits like fix letter
, one quick fix
, etc we should use fixup
or squash
For example we forgot to remove console.log()
from our code but already commited the code. We sould do next
git add <file>
git commit --fixup <commit hash>
after this action git creates commit with same name as your commit that you want to fix and fixup!
at the beginning. You can check it in commit history
next step is interactive rebase
git rebase -i --autosquash
then save and close editor (:wq
)
that's it
...
Go to GitHub after pushing commits. Then go Pull requests
, New pull request
, in base select master
in compare select feature/my-feature
. Then press Create pull request
. If you pretty often used --rebase
github will able to merge code automatically, if you you'll know and you should resolve conflicts, and after that push commits again.
When you create PR
let know your teammates about it and give link to that PR
. Two of them must leave OK as comment, or leave suggestions how to improve you code.
If you see two or more OKs you author can merge branches via GitHub interface. After that author can remove his branch from remote.
You can see this graph at GitHub Graphs
-> Network
.
Shift + Arrow Right
to see latest commits