Example of an entire git workflow with rebasing
git clone ssh://[email protected]/project/repo.git
git checkout -b EXAMPLE-625-jira-ticket origin/develop
to branch off a remote
git commit -a -m 'Fixes issue in EXAMPLE-625'
git push origin EXAMPLE-625-jira-ticket
git commit -a -m 'Another fix'
git push origin EXAMPLE-625-jira-ticket
git fetch --all
Develop branch has changes (now in your remote)
Rebase your branch onto develop, i.e. append your changes onto origin/develop
but inside your branch.
git rebase origin/develop EXAMPLE-625-jira-ticket
Now all you commits are ahead of the latest origin/develop
branch. Clean!
Now we want to squash (condense) our commits into a small number of more meaningful commits (to not include minor changes like 'fixed a quote mark' in final commit that's merged with master)
We start this by checking the previous commits
git log --oneline
look back at the commits and find out at which point we want to squash from (usually from when we branched from master)
Interactive (-i
) rebase of this branch's commits.
Use fixup to squash it, & reword to rename the commit - we will fixup to condense the commit, but reword one of them to describe the condensed changes generally
git rebase -i <commit hash>
We will now force the rebased (condensed) commits onto our branch's remote - ready for merging with master on the server
git push origin EXAMPLE-625-jira-ticket --force-with-lease
(ensures no overwrite of someone else's commits)
Now IN THEORY you can merge into develop although in practice this process is automated on the server. This is done via Pull Requests - so code can be reviewed.