git: Git Flow vs Trunk Based Development

Git Flow:

  • problems:
    • long-lived feature branches and merge hell (i.e. merge conflicts with other people’s code):
    • database migrations – e.g. a db migration living in a long-lived feature branch

Trunk Based Development: release from tagged branches off master

  • short-lived branch and merge – one core rule: deploy a new commit to trunk every day
  • revert commit (if something ends up in production that you don’t want)
  • to avoid delivering code of an unfinished feature: branch by abstraction, feature flag
  • one button rollbacks (i.e. in CI/CD pipeline)
  • automated smoke tests in production that automatically roll back code if it fails a test
  • commit directly to master


git: remove secrets from history

Let’s say you’ve accidentally added a password into git. Here’s how you remove it:

1. if you have only committed locally

a. and it’s your last commit

  • just edit the file and run `git commit -a –amend`

b. and it’s a previous commit

  • do an interactive rebase with git rebase -i origin/master
  • change the pick to edit where you want to edit
  • amend the commit with git commit --amend
  • and continue with git rebase --continue

2. if you have committed and pushed to GitHub

git and Sublime Text integration

I’ve tried GitSavvy and struggled using it.

I like Sublime Merge.

Install with Command Palette (Ctrl Shift P), Install, Sublimemerge 3.

Then use via Command Palette. E.g. blame > Sublime Merge: Blame File will launch a new window showing tons of detail.

Also, if you’re wanting Blame integration, take a look at Blame Explorer. Once installed just hover over the line number in a file to see the change log.

git: error: Your local changes to the following files would be overwritten by merge

You’ve got some local changes in your git repo. What to do?

1. you want to keep your changes

a. and track them

git add <local-changes>; git commit -m "<your message>"

b. but don’t want to track them

Note: if you’re doing a git pullthen:

git update-index --assume-unchanged <file>

will still result in error: Your local changes to the following files would be overwritten by merge

git: what to do with untracked files

I tried --skip-worktree which didn’t work so just moved my .gitignore file (which was causing the problem) out of the way.


2. you don’t want your changes

git co <local-changes>

git: what to do with untracked files

Either track or ignore.


Track: Add untracked file to another branch

I’ve got a branch dev/branch with untracked files A, B.

I’m happy to delete or stash B but I’d like to add A to another branch test/branch.

How do I do that?


The easiest would have been if you were happy to stash them all. Then you could do git stash --all(which includes untracked and ignored files).


But, this has multiple parts.

1. let’s get rid of B

If we don’t know what to do with B, e.g. you don’t have time to look at it, then stash it. Otherwise, delete it.

  • stash:

git add B; git stash

  • delete:

rm B

2. let’s move A to test/branch

git checkout test/branch

git add A




Current docs say working directory but, as of 2.9.1, will read working tree.


Ignore: just ignore untracked files

I’ve got a feature branch with a custom entry in .gitignore to ignore *.out.

However, I now checkout masterand find I’ve got a whole load of untracked files.

I don’t want to add it to the global .gitignore as I don’t want to change the behaviour for other developers.

Neat trick: add it to .git/info/exclude which acts as a local .gitignore.


Note: if you just want to temporarily exclude a file you can use:

git update-index --assume-unchanged <file>



RANT: I’m so sick of having to think about making my gitrepo clean again. I actually used to take a copy of the directory so I could just blast away the directory if I suspected I was going to end up in a messy git state.

Even git reset hard HEAD (I can’t even remember (or be bothered) trying to check I’ve got the right syntax) ) doesn’t always work – e.g. if you’ve got untracked files you’ve still got to remove them manually.

I finally tracked down the code to completely reset your git repo – the short and intuitive:

git reset --hard && git clean -dfx

Or if you have zsh then simply:


Way to go!


git rebase: CONFLICT

git rebase master
First, rewinding head to replay your work on top of it…
Applying: using feature branch for now
Applying: building from feature branch
Using index info to reconstruct a base tree…
M file/A
Falling back to patching base and 3-way merge…
Auto-merging file/A
CONFLICT (content): Merge conflict in file/A
error: Failed to merge in the changes.
Patch failed at 0002 building from feature branch
Use ‘git am –show-current-patch’ to see the failed patch

Resolve all conflicts manually, mark them as resolved with
“git add/rm <conflicted_files>”, then run “git rebase –continue”.
You can instead skip this commit: run “git rebase –skip”.
To abort and get back to the state before “git rebase”, run “git rebase –abort”.