Install Git
On Ubuntu and Debian:
sudo apt update
sudo apt install gitOn AlmaLinux and Rocky Linux:
sudo dnf install gitBoth commands install the command-line client and its dependencies. Nothing has to be started afterward: Git is a program you run, not a service.
Check the Version
git --versionThe output is one line that starts with git version followed by the release number. If the shell says the command is not found, the installation did not finish; run the install command again and read its last lines for an error.
Set Your Name and E-mail
Every commit records an author. Set it once for your user account:
git config --global user.name "Your Name"
git config --global user.email YOUR_EMAILReplace YOUR_ with the address you use on your Git hosting service, so commits are linked to your account there. To use a different identity in one repository, run the same commands inside it without --global.
Check what Git will use:
git config --list --show-originChoose the Default Branch Name
When you create a repository with git init, Git names the first branch master unless you tell it otherwise, and prints a hint about it. Most hosting services now use main. Set the same name locally, so new repositories match:
git config --global init.defaultBranch mainThis setting works in Git 2.28 and later, which every supported distribution release ships. The Git project plans to make main the default in Git 3.0; setting it yourself gives the same result on every version. It changes only new repositories; existing ones keep their branch names.
Other Useful Settings
| Command | What it does |
|---|---|
git config --global core.editor nano | Opens nano for commit messages. |
git config --global pull.ff only | Stops git pull from creating merge commits. |
git config --global fetch.prune true | Removes stale remote branches on fetch. |
The pull.ff only setting is explained in git pull vs git fetch.
Where Settings Are Stored
- System:
/etc/gitconfig, for every user, set with--system. - Global:
~/.gitconfig, for your user, set with--global. - Repository:
.git/configinside the project, set with no option.
When the same setting appears in more than one place, the repository value wins, then the global one, then the system one.
Git on a Server
Run Git as the user who owns the project files, for example deploy, not as root. If you run Git in a repository that belongs to another user, recent versions stop with a message about "dubious ownership". The clean fix is to switch to the owner with sudo -u deploy -i. If you trust the folder, you can mark it as safe instead:
git config --global --add safe.directory /var/www/appTo clone a project over HTTPS:
git clone https://github.com/USER/REPO.gitFor private repositories, set up a key as shown in how to use SSH keys with GitHub, and keep files such as .env out of the repository with .gitignore.
Need a Newer Release?
The distribution package is the right choice on a server: it receives security updates with the rest of the system. On Ubuntu, the Ubuntu Git Maintainers team publishes the current stable release in the ppa:git-core/ppa archive if you need a feature the packaged version lacks. If you are new to working on a server over SSH, start with how to use PuTTY to SSH into a server.
Updated:
Linux VPS with Full Root Access
MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.
More Guides
No Limits on Service or Support
You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

- 100% customer satisfaction goal
- Our own hardware
- 24/7 ticket and email support
- 4 countries with locations