Git is the most widely used distributed version control system, and knowing how to install and configure Git on Ubuntu 26.04 is essential for any developer or system administrator. Whether you are managing personal projects, collaborating with a team, or contributing to open-source software, Git provides the tools to track changes, manage branches, and synchronize code across multiple repositories. This guide walks you through the complete process of installing Git on Ubuntu 26.04 Resolute Raccoon, configuring your identity, setting up SSH keys for secure authentication with GitHub and GitLab, and mastering essential workflow commands.
Software Requirements and Linux Command Line Conventions
Category
Requirements, Conventions or Software Version Used
System
Ubuntu 26.04 Resolute Raccoon
Software
Git, OpenSSH client
Other
Privileged access to your Linux system as root or via the sudo command. An active internet connection. A GitHub or GitLab account (optional, for remote repository operations).
Conventions
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command $ – requires given linux commands to be executed as a regular non-privileged user
Install Git and configure it for immediate use on Ubuntu 26.04 with these quick steps.
Git is available directly from the Ubuntu 26.04 default repositories, making the installation straightforward. Before installing, update your package index to ensure you receive the latest available version.
Update the package index: Refresh the APT package cache to pull in the most recent package information.
$ sudo apt update
Install Git: Use APT to install the git package along with any required dependencies.
$ sudo apt install git
Verify the installation: Confirm that Git is installed correctly by checking its version.
$ git --version
This command prints the installed Git version number, confirming the installation was successful.
IMPORTANT
Ubuntu 26.04 ships Git from its default repository. If you need the very latest Git release, you can optionally add the official Git PPA with $ sudo add-apt-repository ppa:git-core/ppa before installing. For most users, the default repository version is sufficient.
Configuring Git User Identity
After installation, the first and most important step is to configure your Git user identity. Every Git commit records the author’s name and email address, so this configuration is required before you can make any commits. Git stores configuration at three levels: system-wide (/etc/gitconfig), global (per-user ~/.gitconfig), and local (per-repository .git/config). The more specific level always overrides the broader one.
Set your global username: This name will appear in the author field of every commit you make.
$ git config --global user.name "LinuxConfig"
Set your global email address: Use the same email associated with your GitHub or GitLab account to ensure commits are properly linked to your profile.
Set the default branch name: By default, git init creates a branch called master. Modern convention and platforms like GitHub use main instead. Set this globally so all new repositories use main from the start:
$ git config --global init.defaultBranch main
Verify your configuration: List all active Git configuration values to confirm the identity settings are in place.
If you work on multiple projects that require different identities, you can override the global settings on a per-repository basis. Navigate to the repository directory and run the same commands without the --global flag:
These local settings apply only to that specific repository and take precedence over your global configuration.
Generating SSH Keys for Git
While Git supports HTTPS authentication, using SSH keys is the preferred and more secure method for authenticating with remote repositories on GitHub and GitLab. SSH key authentication eliminates the need to enter your username and password for every push or pull operation. Additionally, many platforms are phasing out password-based authentication in favor of token or SSH key-based methods.
Generate an Ed25519 SSH key pair: Ed25519 is the recommended algorithm for SSH keys due to its strong security and compact key size.
SECURITY ALERT
Never share your private key file (~/.ssh/id_ed25519). Only the public key (~/.ssh/id_ed25519.pub) should be added to remote services. If you suspect your private key has been compromised, immediately remove the corresponding public key from all services and generate a new key pair.
Essential Git Workflow Commands
With Git installed and configured on your Ubuntu 26.04 system, you are ready to start working with repositories. This section covers the core commands you will use in daily development workflows.
Initializing and Cloning Repositories
To practice the Git workflow, we will use a public sandbox repository at git@github.com:linuxconfig/linuxconfig_project.git. This is an empty repository created specifically for demonstration purposes. In your own workflow, you would replace this URL with your actual project repository.
IMPORTANT
The linuxconfig/linuxconfig_project repository on GitHub is a sandbox used for this tutorial. Feel free to follow along by creating your own empty repository on GitHub or GitLab instead.
To start a new local project and connect it to a remote repository, initialize a repository in your project directory and add the remote:
This creates a hidden .git directory that stores the entire history and configuration for your repository, and links it to the remote on GitHub. Since we configured init.defaultBranch main earlier, the initial branch is already named main. If you skipped that step, rename it now with $ git branch -M main.
Cloning downloads the complete repository, including all branches and commit history, to your local machine.
Staging, Committing, and Pushing Changes
The fundamental Git workflow involves modifying files, staging changes, committing them with a message, and pushing to a remote repository. Let us walk through this using our sandbox repository.
Create a file: Add a simple file to the project to have something to commit.
$ echo "Hello from LinuxConfig.org" > README.md
Check the repository status: See which files have been modified, added, or are untracked.
$ git status
Stage changes: Add specific files or all changes to the staging area.
$ git add README.md
To stage all changed files at once, you can use $ git add . instead.
Commit the staged changes: Record the staged snapshot in the repository history with a descriptive message.
$ git commit -m "Add README with project description"
Push to the remote repository: Upload your local commits to the remote server.
$ git push -u origin main
The -u flag sets origin/main as the default upstream branch, so future pushes require only $ git push.
Pull remote changes: Download and integrate changes from the remote repository into your local branch.
Customizing Git defaults and creating aliases can significantly improve your productivity. These settings are stored in your global ~/.gitconfig file.
Setting the Default Branch Name
We already configured the default branch name to main in the initial setup section using $ git config --global init.defaultBranch main. If you skipped that step or need to rename an existing master branch in a repository, use:
$ git branch -M main
This renames the current branch to main without losing any history.
Setting the Default Editor
Git uses an editor for writing commit messages, interactive rebases, and other tasks. Set your preferred editor globally:
$ git config --global core.editor "nano"
Replace nano with vim, code --wait (for VS Code), or any other editor of your choice.
Creating Useful Aliases
Aliases let you define shortcuts for frequently used Git commands. Here are some commonly used examples:
After setting these aliases, you can use git st instead of git status, git co instead of git checkout, and so forth.
Credential Caching for HTTPS
If you use HTTPS URLs instead of SSH for remote repositories, you can configure Git to cache your credentials so you do not need to re-enter them for every operation:
$ git config --global credential.helper cache
By default, credentials are cached for 15 minutes. To extend this to one hour:
For a permanent store that saves credentials to disk (less secure, but convenient for personal machines):
$ git config --global credential.helper store
IMPORTANT
The store credential helper saves your credentials in plain text at ~/.git-credentials. Use this option only on personal machines where security is not a major concern. For shared or production systems, prefer SSH keys or the cache helper with a reasonable timeout.
Conclusion
You have successfully installed and configured Git on your Ubuntu 26.04 Resolute Raccoon system. Starting from the APT installation, you set up your user identity, generated SSH keys for secure authentication with GitHub and GitLab, learned the essential workflow commands for daily use, and customized Git with aliases and sensible defaults. Git is now ready to serve as the backbone of your development workflow. For more advanced topics, consult the official Git documentation, which covers topics such as rebasing, stashing, submodules, and hooks in detail.
Frequently Asked Questions
How do I update Git to the latest version on Ubuntu 26.04? If you installed Git from the default Ubuntu repository, run $ sudo apt update && sudo apt upgrade git to get the latest packaged version. For the absolute latest release, add the Git PPA with $ sudo add-apt-repository ppa:git-core/ppa before upgrading.
Can I use both SSH and HTTPS for different Git repositories? Yes. The authentication method is determined by the remote URL of each repository. Repositories cloned with git@github.com:... use SSH, while those cloned with https://github.com/... use HTTPS. You can change a repository’s remote URL at any time with $ git remote set-url origin <new-url>.
How do I check which Git configuration values are active and where they come from? Run $ git config --list --show-origin to display all active settings along with the file path where each value is defined. This is particularly useful when troubleshooting unexpected behavior caused by conflicting settings across system, global, and local configuration files.
What is the difference between git pull and git fetch? The git fetch command downloads new data from the remote repository but does not modify your working directory or current branch. The git pull command performs a fetch followed by a merge, automatically integrating the remote changes into your current branch. Using git fetch first gives you the opportunity to review changes before merging them.
How do I remove Git from Ubuntu 26.04? To uninstall Git and remove its configuration files, run $ sudo apt purge git. Note that this does not remove your personal Git configuration file at ~/.gitconfig or any repositories on your system. Delete those manually if needed.