Skip to content

Latest commit

 

History

History
82 lines (53 loc) · 2.25 KB

File metadata and controls

82 lines (53 loc) · 2.25 KB

Version Control

Using Git is hard and messing up is easy.

Refer to Oh Shit, Git!?! (or the profanity free version: Dangit, Git!?!).

Tower offer a free ebook and also have a comprehensive FAQ.

Branching strategy

Agree on a branching strategy that fits the team's workflow.

Feature based development

  • Gitflow - a popular strategy for feature based development.
  • OneFlow - an evolution of Gitflow to be more efficient and linear.

Trunk based development

Trunk-based development is more suited to DevOps teams using CI/CD.

Renaming branches

  1. Checkout the branch and rename it.

    git branch -m new-name

If the branch has previously been pushed to the remote, it will need renaming there as well.

  1. Push to the remote:

    1. :old-name deletes the branch with the old name.
    2. new-name creates the branch with the new name.
    git push origin :old-name new-name
  2. Set the remote tracking reference for the new branch.

    git push -u origin new-name

Squashing commits

During merge

git checkout master
git merge --squash feature/my-feature

During development

  1. Start an interactive rebase on the commit prior to the commit that other commits will be squashed onto.

    git rebase -i HEAD~4
  2. Select the commits to be squashed, by replacing pick with s.

    pick ca4b127 Working on new feature
    s 2050f54 Some changes
    s 77e50eb Some more changes
    s 1853c79 Fixed stuff
  3. Save the choices (:x if using vi).

  4. Update the commit message and save to finish the rebase.

  5. Force push to the remote, if necessary.

Commit author and time

Sometimes it's necessary to reset the commit author an time, e.g. when squashing commits on a feature branch before merging to master.

git commit --amend --reset-author --no-edit