A Guide to Git with Trunk Based Development

Learn the mindset and process behind Trunk Based Development

- name: content
repository: http://bucketrepo/bucketrepo/charts/
version: 0.0.75
- name: mongodb-replicaset
repository: https://kubernetes-charts.storage.googleapis.com/
version: 3.15.1
- name: person-model
repository: http://bucketrepo/bucketrepo/charts/
version: 0.0.20
- name: www
repository: http://bucketrepo/bucketrepo/charts/
version: 0.0.55

What exactly is in git history?

General Workflow

git fetch

git fetch --all -p
> git fetch --all -pFetching origin
From github.com:servicebus/kafkabus
- [deleted] (none) -> origin/renovate/mocha-7.x
remote: Enumerating objects: 150, done.
remote: Counting objects: 100% (150/150), done.
remote: Compressing objects: 100% (58/58), done.
remote: Total 198 (delta 125), reused 97 (delta 92), pack-reused 48
Receiving objects: 100% (198/198), 362.90 KiB | 1.31 MiB/s, done.
Resolving deltas: 100% (144/144), completed with 6 local objects.
98169c3..6b4ca35 master -> origin/master
* [new branch] renovate/commitizen-4.x -> origin/renovate/commitizen-4.x
* [new branch] renovate/kafkajs-1.x -> origin/renovate/kafkajs-1.x
* [new tag] v2.0.1 -> v2.0.1
* [new tag] v2.0.2 -> v2.0.2
* [new tag] v2.0.3 -> v2.0.3
* [new tag] v2.0.4 -> v2.0.4
> git logcommit 98169c3fabf3052dd89fe0c6900bc3c11a0252a4 (HEAD -> master, tag: v2.0.3)
Author: Patrick Lee Scott <pat@patscott.io>
Date: Sat May 23 13:48:00 2020 -0400
fix: high throughput test already uses no transactions# ... more commits ...

Working on a fix directly against the Trunk branch

git rebase

git rebase origin/master
> git rebase origin/masterFirst, rewinding head to replay your work on top of it...
Fast-forwarded master to origin/master.
> git log# ... your commits ...commit 6b4ca353091a7d6a9eeba8ee5b1978112a81cabf (HEAD -> master, origin/master, origin/HEAD)
Author: Renovate Bot <bot@renovateapp.com>
Date: Wed Nov 4 06:34:00 2020 +0000
chore(deps): update dependency jest to v26.6.3

Working on a branch that will be merged into Trunk via a Pull Request

git rebase -i origin/master

pick f7f3f6d Change my name a bit
pick 310154e Update README formatting and add blame
pick a5f4a0d Add cat-file
# Rebase 710f0f8..a5f4a0d onto 710f0f8
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# . create a merge commit using the original merge commit's
# . message (or the oneline, if no original merge commit was
# . specified). Use -c <commit> to reword the commit message.
# These lines can be re-ordered; they are executed from top to bottom.
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
# Note that empty commits are commented out
pick f7f3f6d Change my name a bit
squash 310154e Update README formatting and add blame
s a5f4a0d Add cat-file
r f7f3f6d Change my name a bit
s 310154e Update README formatting and add blame
s a5f4a0d Add cat-file

git push origin/<branch> —force

Rebasing when you have unsaved changes

> git rebase origin/master
error: cannot rebase: You have unstaged changes.
error: Please commit or stash them.

git stash

git stash
git fetch --all -p
git rebase origin/master
git stash pop


git rebase origin/master --autostash


I make things for the internet, that scale, look nice, and make money!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store