tech-docs

Git

Background

Home Page - Git

Migration from CVS

I have documented the activities that I performed when migrating from CVS to Git.

SourceTree

I perform most Git activities via the command line but I have also been using SourceTree as a GUI.

Home Page - SourceTree

GitFlow

Links:

SSH Keys

To avoid being prompted for username and password for every “push” it is advisable to use SSH keys.

Local

Create your SSH key as follows:

ssh-keygen -t rsa -b 4096 -C "someone@somewhere.com"

Start the ssh-agent and add the key:

eval $(ssh-agent -s)
ssh-add ~/.ssh/id_rsa

Tip: You can add the above lines to ~/.profile so that it is done automically.

GitHub

Copy / paste the public key into the SSH Keys page on GitHub:

cat ~/.ssh/id_rsa

Colours

Change the colours for command line output using the following commands:

# git config --global color.ui auto
git config --global color.diff.old "cyan"
git config --global color.status.untracked "cyan"
git config --global color.status.changed "yellow bold"

White Space

It may be preferable to filter / ignore minor changes sometimes, such as changes to line feeds:

git -c core.fileMode=false -c core.safecrlf=false status
git -c core.fileMode=false -c core.safecrlf=false diff

To filter / ignore changes to file permissions you can do something similar:

git -c core.fileMode=false status
git -c core.fileMode=false diff

Troubleshooting

If you still get prompted for the username then Git might be using https instead of ssh.

Edit the URL line(s) in .git/config:

url = https://github.com/USERNAME/REPOSITORY.git
...
url = ssh://git@github.com/USERNAME/REPOSITORY.git

Releases

Tagging

A couple of my projects use Git tags to trigger automated builds on DockerHub:

Both use lightweight tags as described in the basics of tagging.

git tag <tagname>
git push origin <tagname>

Commit IDs

The git revision can be useful for CI/CD builds since it is unique and can be useful as a Docker tag.

Here are two simple commands to get the Git commit id:

git describe --always --abbrev=12
git rev-parse --short=12 HEAD

Repository Maintenance

Shrinking a Repository

It is sometimes desirable to delete files from the Git repository.

This might be necessary if large files have been committed by accident or if a project needs to be split.

I have made some notes on shrinking a repository.

Connecting to GitHub with SSH

Generating a new SSH key and adding it to the ssh-agent