Skip to content

Uninstall Git on Linux Agent

Overview

If you manually installed Git on your Linux agent and it's causing authentication issues, you can uninstall it and use the Git that comes with the Azure DevOps agent or the system package manager.

Check Current Git Installation

First, identify how Git was installed:

# Check Git version and location
which git
git --version

# Check if installed via package manager
dpkg -l | grep git  # Ubuntu/Debian
rpm -qa | grep git   # CentOS/RHEL

# Check if installed from source
ls -la /usr/local/bin/git
ls -la /opt/git

Uninstall Methods

Ubuntu/Debian:

# Remove Git and related packages
sudo apt remove git git-core
sudo apt purge git git-core
sudo apt autoremove

# Verify removal
git --version  # Should show "command not found" or use system Git

CentOS/RHEL:

# Remove Git
sudo yum remove git
# or
sudo dnf remove git

# Verify removal
git --version

Method 2: Remove Manually Installed Git

If Git was installed from source or manually:

# Find Git installation
which git
# Example output: /usr/local/bin/git

# Remove Git binary
sudo rm -f /usr/local/bin/git
sudo rm -f /usr/local/bin/git-*

# Remove Git man pages
sudo rm -rf /usr/local/share/man/man1/git*
sudo rm -rf /usr/local/share/man/man5/git*
sudo rm -rf /usr/local/share/man/man7/git*

# Remove Git documentation
sudo rm -rf /usr/local/share/doc/git*

# Remove Git configuration (if any)
sudo rm -rf /usr/local/etc/gitconfig

Method 3: Remove Git from Custom Location

If Git was installed to a custom location:

# Find all Git installations
find /usr -name git 2>/dev/null
find /opt -name git 2>/dev/null
find /usr/local -name git 2>/dev/null

# Remove found installations
sudo rm -rf /path/to/git/installation

Clean Up Git Configuration

After uninstalling, clean up any remaining Git configuration:

# Remove global Git config
rm -f ~/.gitconfig
rm -f ~/.git-credentials

# Remove system Git config (if exists)
sudo rm -f /etc/gitconfig

# Clean up any cached credentials
rm -rf ~/.git-credential-cache

Verify Uninstallation

# Check if Git is still accessible
which git
git --version

# Should show "command not found" or use system Git if still installed via package manager

Reinstall System Git (Optional)

If you need Git but want the system version:

Ubuntu/Debian:

sudo apt update
sudo apt install git

CentOS/RHEL:

sudo yum install git
# or
sudo dnf install git

Restart Agent Service

After uninstalling Git, restart the agent service:

cd ~/azagent
sudo ./svc.sh stop
sudo ./svc.sh start

# Verify agent is running
sudo ./svc.sh status

Notes

  • The Azure DevOps agent includes its own Git, so you may not need a system-wide Git installation
  • If you uninstall Git completely, ensure the agent's bundled Git is accessible
  • Some pipelines may require Git to be in PATH - verify your pipeline requirements
  • After uninstalling, test your pipelines to ensure they still work

Troubleshooting

If pipelines fail after uninstalling Git:

  1. Check agent logs:

    sudo journalctl -u vsts.agent.*.service -n 50
    

  2. Verify agent can access repositories:

  3. Check if agent has proper permissions
  4. Verify network connectivity to Azure DevOps

  5. Reinstall Git if needed:

    sudo apt install git  # Ubuntu/Debian