MeshWorld India Logo MeshWorld.
git ubuntu version-control ssh linux 8 min read

Install and Configure Git on Ubuntu 26.04

Jena
By Jena
| Updated: Apr 26, 2026
Install and Configure Git on Ubuntu 26.04

Git is the most widely used distributed version control system. Whether you’re managing personal projects, collaborating with a team, or contributing to open-source, Git provides the tools to track changes, manage branches, and synchronize code. This guide covers installing Git on Ubuntu 26.04, configuring your identity, setting up SSH keys for secure authentication, and mastering essential workflow commands.

[!TIP] Real-World Scenario: You just spent three hours refactoring a component, only to realize you deleted the wrong file. This is the moment you’re grateful for Git—the time machine every developer needs to avoid a total meltdown.

TL;DR
  • sudo apt install git — install Git
  • git config --global user.name "Your Name" — set username
  • git config --global user.email "you@example.com" — set email
  • git config --global init.defaultBranch main — set default branch
  • ssh-keygen -t ed25519 -C "you@example.com" — generate SSH key
  • git config --list — verify configuration

Prerequisites

Before you start, you need:

  • Ubuntu 26.04 with sudo access
  • An active internet connection
  • GitHub or GitLab account (optional, for remote repository operations)

How do I install Git?

Git is available directly from Ubuntu 26.04 repositories. Update your package index and install:

bash
sudo apt update
sudo apt install git

Verify the installation:

bash
git --version

Expected output shows Git 2.53.0 or similar.

Information

Ubuntu 26.04 ships Git from its default repository. If you need the very latest release, add the official Git PPA:

bash
sudo add-apt-repository ppa:git-core/ppa

For most users, the default repository version is sufficient.

How do I configure my Git identity?

Every Git commit records the author’s name and email. Configure this before making any commits. Git stores configuration at three levels: system-wide (/etc/gitconfig), global (~/.gitconfig), and local (.git/config). More specific levels override broader ones.

Set Global Identity

bash
git config --global user.name "Your Name"
git config --global user.email "you@example.com"

Use the same email associated with your GitHub or GitLab account to ensure commits link properly to your profile.

Set Default Branch Name

Modern convention uses main instead of master. Set this globally:

bash
git config --global init.defaultBranch main

Verify Configuration

bash
git config --list

Per-Repository Configuration

For projects requiring different identities, override global settings locally:

bash
cd ~/your_project
git config user.name "Different Name"
git config user.email "other@example.com"

These local settings apply only to that repository.

How do I set up SSH keys for GitHub?

SSH key authentication is the preferred, more secure method for authenticating with GitHub and GitLab. It eliminates entering credentials for every push or pull.

Generate an Ed25519 SSH Key Pair

Ed25519 is the recommended algorithm due to its strong security and compact key size:

bash
ssh-keygen -t ed25519 -C "your-email@example.com"

Press Enter to accept the default file location (~/.ssh/id_ed25519). Optionally set a passphrase for additional security.

Start the SSH Agent

bash
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

The SSH agent manages keys in memory so you don’t need to enter the passphrase repeatedly.

Copy the Public Key

bash
cat ~/.ssh/id_ed25519.pub

Copy the entire output (starts with ssh-ed25519).

Add the Key to GitHub or GitLab

GitHub: Settings → SSH and GPG keys → New SSH key. Paste the public key and save.

GitLab: Preferences → SSH Keys. Paste the public key, set an optional expiration, and save.

Test the SSH Connection

bash
ssh -T git@github.com

A successful connection returns a greeting message with your username. For GitLab, use git@gitlab.com instead.

Warning

Never share your private key file (~/.ssh/id_ed25519). Only the public key (~/.ssh/id_ed25519.pub) should be added to remote services. If your private key is compromised, immediately remove the corresponding public key from all services and generate a new key pair.

What are the essential Git commands?

Initializing and Cloning Repositories

Start a new local project:

bash
mkdir ~/my_project
cd ~/my_project
git init
git remote add origin git@github.com:username/repo.git

Or clone an existing repository:

bash
git clone git@github.com:username/repo.git

Staging, Committing, and Pushing

The fundamental Git workflow:

bash
# Create or modify files
echo "# My Project" > README.md

# Check repository status
git status

# Stage changes
git add README.md
# Or stage all changes: git add .

# Commit with a descriptive message
git commit -m "Add README with project description"

# Push to remote repository
git push -u origin main

The -u flag sets origin/main as the default upstream branch. Future pushes require only git push.

Pull remote changes:

bash
git pull origin main

Working with Branches

Create and switch to a new branch:

bash
git checkout -b feature-login

This combines git branch feature-login and git checkout feature-login.

Merge a branch back into main:

bash
git checkout main
git merge feature-login

List all branches:

bash
git branch -a

Viewing History

Review commit history:

bash
git log --oneline --graph --all

This produces a condensed visual representation of branch and merge history.

How do I customize Git with aliases?

Setting the Default Editor

Git uses an editor for commit messages and interactive rebases:

bash
git config --global core.editor "nano"

Replace nano with vim, code --wait (for VS Code), or your preferred editor.

Creating Useful Aliases

Aliases define shortcuts for common commands:

bash
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.lg "log --oneline --graph --all --decorate"

After setting these, use git st instead of git status, git co instead of git checkout, etc.

Credential Caching for HTTPS

If using HTTPS instead of SSH, cache credentials to avoid re-entering them:

bash
git config --global credential.helper cache

Default cache time is 15 minutes. Extend to one hour:

bash
git config --global credential.helper 'cache --timeout=3600'

For permanent storage (less secure, convenient for personal machines):

bash
git config --global credential.helper store
Warning

The store helper saves credentials in plain text at ~/.git-credentials. Use only on personal machines. For shared systems, prefer SSH keys or the cache helper.

Summary

  • Install Git with sudo apt install git
  • Configure identity with git config --global user.name and user.email
  • Generate SSH keys with ssh-keygen -t ed25519 for secure authentication
  • Use git init to start repositories, git clone to copy existing ones
  • Stage changes with git add, commit with git commit -m, push with git push
  • Create branches with git checkout -b, merge with git merge
  • Customize with aliases to speed up your workflow

FAQ

How do I update Git to the latest version? If installed from the default repository:

bash
sudo apt update && sudo apt upgrade git

For the absolute latest, add the Git PPA first.

Can I use both SSH and HTTPS for different repositories? Yes. Authentication is determined by the remote URL. Repositories cloned with git@github.com:... use SSH, while https://github.com/... use HTTPS. Change a remote URL anytime:

bash
git remote set-url origin <new-url>

How do I check which Git configuration values are active?

bash
git config --list --show-origin

This displays all settings with the file path where each is defined.

What is the difference between git pull and git fetch? git fetch downloads new data without modifying your working directory. git pull performs a fetch followed by a merge, integrating remote changes. Using git fetch first lets you review changes before merging.

How do I remove Git from Ubuntu 26.04?

bash
sudo apt purge git

This doesn’t remove your personal ~/.gitconfig or repositories. Delete those manually if needed.