Repo-specific Git Config

  • henok_mikre

    Henok Mikre

We needed to set a repository specific .gitconfig for one of our projects. We discovered that we could use the git config --local flag to make this happen. However, the server on which we wanted to do this had git version 1.7.1. The --local flag is not available in that version of git. If we go by the entry for it in the documentation, it was first mentioned in git-config.txt in June of 2013 (commit: 560d4b8). And that commit was first released in v1.8.3.4. Anyway, an upgrade was necessary. And if we're going to upgrade, we might as well upgrade to the latest version.

This dev server for this project is running CentOS 6 in order to match the client environment:

# Check OS
cat /etc/*release*
CentOS release 6.8 (Final)
CentOS release 6.8 (Final)
CentOS release 6.8 (Final)
cpe:/o:centos:linux:6:GA

Upgrading from git 1.7 to 2.8 on CentOS

# Check what version of git current repo's provide
yum provides git
git-1.7.1-4.el6_7.1.x86_64 : Fast Version Control System

# Get IUS repo setup script
curl 'https://setup.ius.io/' -o setup-ius.sh

# Run setup script
sudo sh setup-ius.sh

# Recheck available versions
yum provides git
git2u-2.9.2-1.ius.centos6.x86_64 : Fast Version Control System
git-1.7.1-4.el6_7.1.x86_64 : Fast Version Control System

# Check what version of git the repo provides
yum --enablerepo=ius list git*

# Remove old git
sudo yum remove git

# Install git from new repo
sudo yum --enablerepo=ius install git2u

# Verify version
git --version
git version 2.9.2

Now that we have the latest version of Git, we can tell it to use our local .gitconfig:

# Change into repo
cd repo/

# Check git config
cat .gitconfig
[core]
  autocrlf = input

# Tell git to include local config
git config --local include.path ../.gitconfig

# Verify
git config core.autocrlf
input

On to the next one...

Resources

Let's work together to deliver a success story.