Best Git Practices For Managing Your Project

Having troubles managing git history in your project? You should read this.

Creating new branches

Main branches

  • master branch
  • develop branch

Support branches

  • Feature branches (for ex. feature/<TASK_ID>-Short-feature-description)
  • Defect branches (for ex. defect/<TASK_ID>-Short-defect-description)
  • Release branches (for ex. release/<release_version>)
  • Hotfix branches (for ex. hotfix/<short_hotfix_description>)

Committing

Use proper naming!

  • “added ui”
  • “added logic”
  • “resolved PR comments part 2”
  • “rebasing”
  • etc.

Preferably, use one of these approaches:

Amending commits

git commit --amend
git push -f origin feature/ABC-123_Some_cool_feature

Merging VS Rebasing

Merging

Rebasing

The Verdict

Useful git commands that you MUST learn to save yourself in critical situations

Git stash

Git status

Git log

Git reflog

Git reset (soft/mixed/hard)

Git rebase interactive

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

Git cherry pick

Wow, that’s a lot of new git commands

--

--

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
Patryk Kosieradzki

Patryk Kosieradzki

Senior Android Engineer @ Moss, Podcaster @ AndroidTalks, based in Warsaw, Poland