Git workflow

These are our Git principles:

  1. Follow the simple git branching model.
  2. Follow the angular git commit guidelines (e.g. useĀ commitizen cli).

Additional best practices

  • Make many small commits.
  • Push your commits to remote immediately.
  • Create and review pull requests timely.
  • Delete remote & local branches after accepting pull requests.
  • Prune branches locally to stay on top of things.

Create a new branch

Topic or feature branches must be created off of the up-to-date main branch.

git checkout main
git fetch
git merge origin/main
git co -b {topic}

Commit changes

  • Do not commit unused or unnecessary code (check with git diff).
  • Use meaningful commit messages.

There are several ways to stage/add/commit your changes.

  1. The easiest one commits every change you made:
git add .
git commit -m '{meaningful_commit_message}'
  1. To commit only modified files, not new ones, do the following:
git commit -am '{meaningful_commit_message}'
  1. To review and commit only selected files or parts, use partial-file staging:
git add -p [{filepath}]
git commit -m '{meaningful_commit_message}'
  1. To commit specific files only (new or modified):
git add {filepath}
git commit -m '{meaningful_commit_message}'

Merge a branch

If you merge a branch, there might be merge conflicts. Solve all conflicts and commit with the automatically generated commit message.

git add . (or) git add -p
git commit -m (or) git commit --continue

This might open vim. To save and quit type :wq and press the enter-key.

Push a branch

Before creating a pull request, merge the main branch into your branch.

git checkout {topic}
git fetch
git merge origin/{topic}
git merge origin/main
git push origin {topic}

Pull request

After the pull request was merged, update your local branches.

git checkout main
git fetch
git merge origin/main
git branch -d {old_topic}
git remote prune origin