Git

It is recommended to learn a little about the theory behind Git before diving in. Codecademy has a free course. This cheat sheet is also helpful.

Contents

Installation

Refer to the official documentation.

GUI Clients

Git Configuration

Auditing configuration

It helps to first audit your Git configuration to find any existing configuration files.

To view all configured settings by configuration file, run:

$ git config --list --show-origin 

Keep in mind there may be multiple configuration files on your system. You might need admin/root access to edit some of them.

Typical paths for Git configuration files:

  • ~/.config/git/config
  • ~/.gitconfig

Basic configuration options

To set a global configuration value quickly on the command line, use:

$ git config --global group.name value 

Note that you must use quotation marks for strings on command line

Windows line endings

We want to use LF on all files in our repositories to maintain multi-platform compatibility.

Setting core.autocrlf input should keep all files LF and converting them from CRLF on commit if necessary, but not the other way around.

$ git config --global core.autocrlf input

If you need to change the line endings of a Windows workspace from CRLF to LF, set core.autocrlf = false and then run on all repos:

git add --renormalize .
git checkout -- .

# Or using vcstool:
vcs custom -n -w 1 repos --args add --renormalize .
vcs custom -n -w 1 repos --args checkout -- .

You may need to unstage and discard local changes after doing this.

Saving credentials permanently

Ubuntu

Ensure your git config is using libsecret as the credential helper. libsecret stores your credentials in a secure manner.

git config --global credential.helper libsecret

We need to build libsecret for this to work.

sudo apt install -y libsecret-1-0 libsecret-1-dev
cd /usr/share/doc/git/contrib/credential/libsecret
sudo make
git config --global credential.helper /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret

Now, you should be able to perform git operations without having to type in your credentials every time.

Windows

Installing Git bash and authenticating once by cloning some private repository (or any other authenticated git request) should permanently store your git credentials. Make sure when you install Git bash that you use the "Git Credential Manager".

Git LFS

We use Git LFS (Large File Storage) for storing large files (URDFs, 3D models, shared libraries, images, log data, etc) in our git repositories. Anything above ~5MB should be stored in git-lfs. This reduces clutter in the git version history and allows us to host large files on GitHub.

If you have installed git-lfs after cloning a git-lfs repo, you may need to run git-lfs pull from inside the repository directory.

Installation

If these don't work, try the official guide from GitHub.

Ubuntu

cd ~/Downloads && wget https://github.com/git-lfs/git-lfs/releases/download/v3.5.1/git-lfs-linux-amd64-v3.5.1.tar.gz
tar -xvf git-lfs-linux-amd64-v3.5.1.tar.gz
cd git-lfs-3.5.1
sudo ./install.sh

Windows

Download and extract git-lfs https://github.com/git-lfs/git-lfs/releases/download/v3.5.1/git-lfs-windows-amd64-v3.5.1.zip

Run the extracted .exe installation wizard.

See More