This is an abstract from carbonfive post blogs
Pull master branch
git pull origin master
Create bug/feature branch
git checkout -b branchName
Commit and/or push any modification
Get the number of commits from the start of your branch. There are a couple of ways to get this. You can simply git log and count your commits, or
git log --graph --decorate --pretty=oneline --abbrev-commit
which will show a graph of your commit log history and may be easier to visualize your commits. Sometimes you will have large enough number of commits that counting can become troublesome. In that case grab the SHA from the last commit that your branch branches from.
Squash to 1 commit.
git rebase -i HEAD~[NUMBER OF COMMITS]
OR
git rebase -i [SHA]
dafi note: The editors opens, the commits are shown in reverse order, leave first line with pick
and replace all the following with squash
or simply s
Select the SHA preceding the squash point, in the example below we want to to squash from c6ccf8b
to aeb5301
so we specify the value e92ec53
* c6ccf8b (HEAD -> coroutines-modules, origin/coroutines-modules) removed not-null assertion operator (!!)
* aeb5301 refactored package
* da06207 removed dependency
* f5ce686 moved strings
* 2c8a3b2 fixed lint warnings
* c6ccf8b splitted in modules
* e92ec53 (origin/coroutines, coroutines) refactored PostAction
* 8a01474 call invalidateOptionsMenu() to disable items
* f7c2866 fixed detekt lint warnings
* 858fa5d disable menu items while misspelling check is in progress
If you have previously pushed your code to a remote branch, you will need to force push.
git push origin branchName --force
dafi note: consider to use the flag --force-with-lease
to be sure do not overwrite other teamwork code
git push origin branchName --force-with-lease
Checkout master branch
git checkout master
Pull master branch
git pull origin master
Checkout bug/feature branch
git checkout branchName
Rebase from master
git rebase master
Handle any conflicts and make sure your code builds and all tests pass. Force push branch to remote.
git push origin branchName --force
Checkout, merge, and push into master
git checkout master
git merge branchName
git push origin master