Skip to content

Instantly share code, notes, and snippets.

@Bolza
Last active April 10, 2017 10:36
Show Gist options
  • Save Bolza/3ce8954a0289d008e23aa63002f77c31 to your computer and use it in GitHub Desktop.
Save Bolza/3ce8954a0289d008e23aa63002f77c31 to your computer and use it in GitHub Desktop.
Git Rebase Flow

Example of an entire git workflow with rebasing

git clone ssh://git@dev.example.com/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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment