Configure Git (VCS) on CentOS 8 or RHEL 8 – Step‑by‑Step
If you’ve just spun up a fresh CentOS 8 or RHEL 8 box and need to start versioning code, the first thing you’ll likely do is get Git installed. Below are the exact commands and explanations that will have your repository ready in minutes—no fluff, no corporate jargon.
Prerequisites
- You’re logged in as a user with sudo privileges (or root).
- Your system has internet access to reach the CentOS/DNF repositories.
Install Git from the Default Repos
sudo dnf install -y git
The base CentOS 8 repos already ship a stable Git build, so you don’t need to pull in EPEL or other PPAs. If you see “No package git available,” your repo metadata may be out of date—run sudo dnf makecache first.
Verify the Installation
git --version
You should see something like git version 2.27.0. A missing command here usually means the install didn’t finish or you’re still in an old shell; restart your terminal if needed.
Configure Your Identity
Git tags every commit with an author name and email, so set those globally:
git config --global user.name "Your Name" git config --global user.email "you@example.com"
If you forget to do this, Git will prompt you at each commit or, worse, default to your system username and the machine’s hostname—bad for blame attribution later.
Generate an SSH Key Pair
ssh-keygen -t ed25519 -C "you@example.com"
Press Enter to accept the default file location (~/.ssh/id_ed25519). Skip the passphrase if you want hands‑free pushes; otherwise, you’ll be prompted each time.
SSH keys are more secure than HTTP passwords and avoid having your credentials stored in plain text. Most services (GitHub, GitLab, Bitbucket) require an SSH key for authenticated Git operations.
Add the Key to the SSH Agent
eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_ed25519
If you see “Could not open a connection to your authentication agent,” make sure the ssh-agent is running or start it manually.
Without adding the key, Git will try password authentication and fail. The agent keeps your private key in memory so you don’t re-enter the passphrase (if you set one) every time.
Test SSH Authentication
ssh -T git@github.com
You should get a message like:
> Hi username! You've successfully authenticated, but GitHub does not provide shell access.
If it says “Permission denied (publickey),” double‑check that you copied the exact public key (~/.ssh/id_ed25519.pub) to your Git hosting account and that the file permissions are 600 for the private key.
Clone a Repository or Start One Locally
To clone:
git clone git@github.com:username/repo.git
To start fresh:
mkdir myproject && cd myproject git init touch README.md git add README.md git commit -m "Initial commit"
git init creates a bare repository locally. Adding and committing right away sets up the first snapshot, which is useful for local backup or when you’re building a new project from scratch.
Optional: Handy Git Aliases
Add these to your global config so you can type less:
git config --global alias.co checkout git config --global alias.br branch git config --global alias.ci commit git config --global alias.st status
Now git co is a quick way to switch branches, and so on.
Common Pitfalls
| Symptom | Likely Cause | Fix |
|---|---|---|
| fatal: could not read Username for 'https://...': terminal prompts disabled | Using HTTPS without credentials. | Switch to SSH (git remote set-url origin git@github.com:user/repo.git) or cache your HTTPS creds with a credential helper. |
| “Permission denied (publickey)” when pushing | Wrong public key on the host, wrong private key permissions, or ssh-agent not loaded. | Re‑add the key to the agent (ssh-add ~/.ssh/id_ed25519) and double‑check you added the public key in your account settings. |
| git: command not found after install | PATH not refreshed in current shell. | Open a new terminal or source /etc/profile. |
I’ve seen this happen when people upgrade their system with dnf upgrade and forget that Git can be removed if the package was explicitly purged. Running sudo dnf reinstall git usually fixes it.
That’s it—your CentOS 8 or RHEL 8 machine is now a fully‑functional version control hub. Time to commit, push, and maybe even set up CI later!