How to Install Git and GitHub CLI on Linux
GitHub is a hosted service, so there is nothing called "GitHub" to install on Linux. What you install is:
- Git, the version control tool that clones, commits and pushes.
- GitHub CLI (
gh), optional but useful: it logs you in to GitHub, handles credentials and works with pull requests, issues and Actions from the terminal.
GitHub Desktop has no official Linux build. Community forks exist, but most people on Linux use the terminal or their editor's Git integration.
Install Git
sudo apt update && sudo apt install git # Ubuntu, Debian
sudo dnf install git # Fedora, RHEL, Rocky, Alma, Amazon Linux 2023
sudo pacman -S git # Arch
git --version
The distribution version is fine for everyday work. If you need a newer Git on Ubuntu, the Git maintainers publish a PPA:
sudo add-apt-repository ppa:git-core/ppa
sudo apt update && sudo apt install git
Configure your identity
Every commit records a name and email. Set them once:
git config --global user.name "Jane Doe"
git config --global user.email "jane@example.com"
git config --global init.defaultBranch main
git config --global --list
If you keep your email private on GitHub, use the noreply address shown under Settings, Emails, so pushes are not rejected by the email privacy setting.
Install GitHub CLI
Use GitHub's own package repository. The gh package in Ubuntu's and Debian's archives lags behind, and the GitHub CLI team warns that some of those old versions no longer work against GitHub's API. The team also discourages the Snap.
Ubuntu and Debian:
sudo mkdir -p -m 755 /etc/apt/keyrings
wget -nv -O- https://cli.github.com/packages/githubcli-archive-keyring.gpg \
| sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null
sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" \
| sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install gh
The key goes into its own keyring file and the repository is bound to it with signed-by, so this key can only sign GitHub's repository.
Fedora 41+ (dnf5):
sudo dnf install dnf5-plugins
sudo dnf config-manager addrepo --from-repofile=https://cli.github.com/packages/rpm/gh-cli.repo
sudo dnf install gh
RHEL, Rocky, AlmaLinux, Amazon Linux 2023 (dnf 4):
sudo dnf install 'dnf-command(config-manager)'
sudo dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo
sudo dnf install gh
dnf asks you to confirm the repository's GPG key on first install. openSUSE uses sudo zypper addrepo https://cli.github.com/packages/rpm/gh-cli.repo followed by sudo zypper install gh, and Arch has it in the official repositories as sudo pacman -S github-cli.
Updates then come with the normal system upgrade.
Log in to GitHub
gh auth login
Choose GitHub.com, then HTTPS or SSH as the protocol for Git, then log in with a browser. On a machine without a browser, such as a server over SSH, gh prints a one-time code that you enter at github.com/login/device from any other device.
If you chose HTTPS, accept the offer to authenticate Git with your GitHub credentials. That makes gh Git's credential helper, so git push over HTTPS just works. You can also set it up later:
gh auth setup-git
gh auth status
GitHub stopped accepting account passwords for Git operations in 2021. Over HTTPS you need either this credential helper or a personal access token.
Use SSH keys instead
If you prefer SSH remotes (git@github.com:...), create a key and register it:
ssh-keygen -t ed25519 -C "jane@example.com"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
Upload the public key with gh, which needs an extra permission scope for that:
gh auth refresh -h github.com -s admin:public_key
gh ssh-key add ~/.ssh/id_ed25519.pub --title "my-laptop"
Without gh, print the key with cat ~/.ssh/id_ed25519.pub and paste it into GitHub under Settings, SSH and GPG keys. Then test:
ssh -T git@github.com
A message starting with "Hi your-username! You've successfully authenticated" means it works. GitHub does not offer a shell, so the connection closes right after. If you chose SSH during gh auth login, it can generate and upload the key for you.
Clone and work
gh repo clone my-org/my-repo # or: git clone git@github.com:my-org/my-repo.git
cd my-repo
git switch -c fix-typo
git commit -am "Fix typo in README"
git push -u origin fix-typo
gh pr create --fill
gh pr status
gh pr create --fill uses the commit messages for the pull request title and body. Other handy commands: gh repo create, gh issue list, gh run watch for GitHub Actions runs.
Quick reference
sudo apt install git # Git on Ubuntu/Debian
sudo dnf install git # Git on Fedora/RHEL
git config --global user.name "Jane Doe"
git config --global user.email "jane@example.com"
sudo apt install gh # after adding cli.github.com repo
sudo dnf install gh # after adding gh-cli.repo
gh auth login # browser or device-code login
gh auth setup-git # gh as Git credential helper
ssh-keygen -t ed25519 -C "jane@example.com" # SSH key
gh ssh-key add ~/.ssh/id_ed25519.pub --title my-laptop # upload it
ssh -T git@github.com # test SSH access
