Git Crash Course
I have been studying Git and here is what I learned.
Updated January 2022
- Last year I used the git branching model as shown here to track versions of a dashboard I built using Google Maps API in GCP, Python, and PowerBI. However I found it hard to follow in a CD environment as described at the beginning of that post. It’s a good process as it’s mentioned, to build software that requires version maintenance. A good example is Kubernetes as seen in the changelog here
- I moved on to using the recommended Github flow for continuous delivery with JIRA integration.
I also missed the bus when they decided to replace the naming convention from master
to main
as seen on the github blog here.
Github flow and JIRA
- Integrate with JIRA
- Protect main branch
- From main, create a branch with the JIRA issue ID.
- Make changes on the branch
- Create a PR
- Merge PR
- Delete branch
Summary
Step 1: Pull main changes, create and work on a branch (lookup JIRA’s issue ID), and push the branch.
$ git checkout main
(main)$ git pull
$ git checkout -b ABC-123/add-login
(ABC-123/add-login)$
(ABC-123/add-login)$ echo "Something" > awesome.txt
(ABC-123/add-login)$ git commit -m "ABC-123 added awesome"
(ABC-123/add-login)$ git push -u origin ABC-123/add-login
Step 2: Go to Github, create a PR, merge, delete branch. Unless working in a team and branch is protected, assign reviewers to PR, wait for approval, then merge (or team will merge).
Loop to Step 1.
Integrate with JIRA
- Follow the integration docs here and integrate with Github here
- The data is automatically linked between JIRA and the repo:
- If the issue key is in the commit message
- If the issue key is in the branch name
- If the issue key is in the PR title or branch name
- If the issue key is in the title of the review
- The issue key must have the syntax
- Exact issue key with uppercase letters a dash and numbers.
- For example
ABC-123
- When making a commit follow this template:
git commit -m "ABC-123 added awesome feature
git push origin <branchname>
Protect main branch