Git
Committing Changes
Commits should, as much as possible, contain changes that relate to a specific feature or ticket. This is to allow them to be reversed later if needed.
The commit message should describe what has changed. If the change relates to a JIRA ticket it should be prefixed with the ticket identifier. This will then create links in Jira/BitBucket (note that this doesn't work if you are working cross instances - for example using the N3 Jira and Internet Bitbucket).
git commit -m "RR-123 I changed function val_banana to add a check for apples"
Moving Committed (but not Pushed) Changes to another branch
This is useful when you try to Push changes to Services to Master and it gets rejected with a message that you need to do this via a pull request.
Run:
git fetch origin
git rebase origin/master
git reset --hard origin/master
(Check before doing this that git status is clear)
Using Multiple Deploy Keys
One way to pull code from Git to a server is to add a public SSH key as a Deploy Key in the Repo Settings. There is a problem though that each Deploy Key can only be used on one GitHub repo which requires multiple Keys. You then have the problem of telling Git which key to use with which repo.
Generate an SSH keypair per repo as usual (albeit with a unique filename) and add it to the repo as a Deploy Key.
Create a .ssh/config file which looks similar to the following -
Host github.com
Hostname github.com
IdentityFile=/home/ukrdc/.ssh/bamboo
Host github.com-data_extract
Hostname github.com
IdentityFile=/home/ukrdc/.ssh/data_extract_key
Host github.com-ukrdc_database
Hostname github.com
IdentityFile=/home/ukrdc/.ssh/ukrdc_database_key
Host github.com-ukrr_quarterly_extract
Hostname github.com
IdentityFile=/home/ukrdc/.ssh/ukrr_quarterly_extract_key
Host github.com-data_extract
This is the important part which we’ll be using in the git clone command. I have used the same value as the repo name (as with the key filenames) but I believe it just needs to be a unique value.
Clone using a command similar to -
git clone git@github.com-data_extract:renalreg/data_extract.git
Note the modified hostname to match the reference in the config file.
The first entry in the config file specifies which key will be used by default where the hostname hasn’t been modified i.e. via pip/poetry.
The key here has had to be added to the “bamboo” build account in GitHub as one of its keys.
If you have had to do this then it does make the use of the deploy keys irrelevant.
Useful reference Articles/Sites
Dangit, Git!?! How to sort errors when committing