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.
sudo apt install git— install Gitgit config --global user.name "Your Name"— set usernamegit config --global user.email "you@example.com"— set emailgit config --global init.defaultBranch main— set default branchssh-keygen -t ed25519 -C "you@example.com"— generate SSH keygit 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:
sudo apt update
sudo apt install git Verify the installation:
git --version Expected output shows Git 2.53.0 or similar.
Ubuntu 26.04 ships Git from its default repository. If you need the very latest release, add the official Git PPA:
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
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:
git config --global init.defaultBranch main Verify Configuration
git config --list Per-Repository Configuration
For projects requiring different identities, override global settings locally:
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:
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
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
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
ssh -T git@github.com A successful connection returns a greeting message with your username. For GitLab, use git@gitlab.com instead.
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:
mkdir ~/my_project
cd ~/my_project
git init
git remote add origin git@github.com:username/repo.git Or clone an existing repository:
git clone git@github.com:username/repo.git Staging, Committing, and Pushing
The fundamental Git workflow:
# 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:
git pull origin main Working with Branches
Create and switch to a new branch:
git checkout -b feature-login This combines git branch feature-login and git checkout feature-login.
Merge a branch back into main:
git checkout main
git merge feature-login List all branches:
git branch -a Viewing History
Review commit history:
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:
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:
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:
git config --global credential.helper cache Default cache time is 15 minutes. Extend to one hour:
git config --global credential.helper 'cache --timeout=3600' For permanent storage (less secure, convenient for personal machines):
git config --global credential.helper store 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.nameanduser.email - Generate SSH keys with
ssh-keygen -t ed25519for secure authentication - Use
git initto start repositories,git cloneto copy existing ones - Stage changes with
git add, commit withgit commit -m, push withgit push - Create branches with
git checkout -b, merge withgit 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:
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:
git remote set-url origin <new-url> How do I check which Git configuration values are active?
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?
sudo apt purge git This doesn’t remove your personal ~/.gitconfig or repositories. Delete those manually if needed.
What to Read Next
- Install and Configure GitLab Runner on Ubuntu 26.04 — set up CI/CD pipelines
- Git Branching Strategies — master feature branch, GitFlow, and trunk-based workflows
- Git Hooks for Automation — automate code quality checks and deployments
Related Articles
Deepen your understanding with these curated continuations.
Install .deb Packages on Ubuntu 26.04
Complete guide to install .deb packages on Ubuntu 26.04 using apt, dpkg, and GDebi. Handle dependencies, verify installations, and troubleshoot common errors.
Install and Configure PostgreSQL on Ubuntu 26.04
Complete guide to install PostgreSQL 18 on Ubuntu 26.04. Set up roles, databases, remote access, authentication methods, and security hardening.
Install and Secure MySQL on Ubuntu 26.04
Complete guide to install and harden MySQL on Ubuntu 26.04. Run mysql_secure_installation, create users and databases, configure remote access with firewall rules.