If you manage applications on Linux servers, you probably pull code over SSH several times a day.
Each operation takes only a few seconds, but the friction adds up when every git log requires multiple flags, git pull stops to ask how to reconcile divergent branches, and GitHub pushes repeatedly prompt for authentication.
Most of these interruptions come from Git and GitHub CLI defaults that do not match your workflow.
A few one-time configuration changes can simplify common commands, make pull behavior predictable, keep repositories maintained, and reduce repeated authentication prompts.
Both Git and the GitHub CLI (gh) support persistent settings, allowing you to apply these improvements without changing your deployment scripts or configuring every command from scratch.
Before changing anything, it helps to understand where Git stores its settings.
Git uses three configuration levels, with more specific settings overriding broader ones:
The examples below use git config –global, so the settings apply to every repository managed by your current Linux user, including tecmint.
Repository-specific settings can still override them.
The GitHub CLI (gh) stores its preferences in ~/.config/gh/config.yml and its authentication information in ~/.config/gh/hosts.yml.
These files serve different purposes: the configuration file controls CLI behavior, while the hosts file stores authentication data for GitHub accounts and hosts.
Git is already installed on many Linux servers, but the GitHub CLI (gh) may be missing.
Install both on the example server, 192.168.122.248, using the commands for your Linux distribution.
On Ubuntu and Debian, install the packages from the configured APT repositories.
The available gh version may lag behind the latest upstream release.
On Rocky Linux, AlmaLinux, and RHEL, Git is available through the standard repositories, but the GitHub CLI may require its official RPM repository.
Add the repository and install gh as follows:
Verify the installed versions before proceeding:
The examples below assume Git 2.34 or newer, which introduced background maintenance scheduling through systemd timers on Linux.
Some commands and options may behave differently with older releases, so check your installed version before applying the configuration.
The first improvement is to reduce repetitive typing.
Git aliases let you assign short names to frequently used commands and their options, making everyday repository checks faster.
Configure these three aliases globally:
Here is what each alias does:
For example, run these commands from your application directory:
You can now check the working tree, inspect recent history, and review the latest commit without repeatedly typing long command options.
Because these aliases use `–global`, they are available in every repository accessed by your current Linux user.
Aliases save keystrokes, but a more disruptive problem is a git pull that stops a deployment with the error fatal: Need to specify how to reconcile divergent branches.
Modern Git displays this message when local and remote branches have diverged and no pull strategy has been configured.
On a deployment checkout, you may want Git to accept only fast-forward updates and stop if the local branch contains commits that are missing from the remote.
Configure that behavior globally:
These settings solve two different problems:
If a pull fails because Git cannot fast-forward, inspect the recent history before changing anything:
If the server contains an unexpected local commit, determine whether it should be pushed, preserved on another branch, or discarded.
Do not reset or discard it blindly, especially on a production server.
The first two hacks speed up your commands, while this one speeds up Git itself.
Frequently pulled repositories collect loose objects and pack files, so Git slows down over months, and an automatic git gc can start in the middle of a deploy.
The git maintenance command moves that housekeeping into scheduled background jobs, so register the repository from inside its directory:
This adds the repository to maintenance.repo in your global config and creates hourly, daily, and weekly systemd user timers (or cron jobs when systemd user services aren’t available), which you can list:
You should see the hourly, daily, and weekly git-maintenance@ timers listed, with next-run times that differ on your server.
User timers only run while you have an active login session, so enable lingering for your user to keep the jobs running after you log out:
With Git itself tuned, the remaining delay comes from GitHub authentication.
GitHub no longer accepts account passwords over HTTPS, so every push asks for a personal access token, while the GitHub CLI can log in once and hand that token to Git whenever it asks.
Start the login from the server:
Choose GitHub.com, HTTPS, and Login with a web browser, then enter the one-time code that GitHub CLI (gh) will display a one-time device code and ask you to open https://github.com/login/device on your own computer, enter the code there and authorize the request.
This method works on headless Linux servers because the browser-based authorization happens on your local computer.
You can check what this changed in your global Git config:
Output:
The empty helper lines look like a mistake, but they are normal because they clear any credential helper defined earlier so Git asks only gh for GitHub credentials.
Now that GitHub CLI (gh) is logged in, tune it the way you tuned Git in the first hack, since its interactive questions leave cron jobs waiting for input that never comes:
Here is what each setting and alias does:
With all five hacks in place, run git config –list –show-origin whenever something behaves unexpectedly, because it shows every active setting next to the file it came from.
To reuse this setup, copy ~/.gitconfig and ~/.config/gh/config.yml to other servers with scp, but never hosts.yml, since on a server without a keyring gh stores your token there in plain text.
On shared servers, avoid your personal GitHub account and use a fine-grained token passed with gh auth login –with-token, limited to the repositories that server deploys, so a compromised server exposes as little as possible.
You now have shorter Git commands, pulls that never create surprise merge commits, background repository maintenance, and GitHub logins that no longer interrupt your work.
Each change took one command, and together they remove most of the waiting from Git work on a server.
To wrap these commands into a deploy script that pulls, checks CI, and restarts your service, our Bash Scripting for Beginners course covers variables, error handling, and exit codes.
We’d love to hear how you’ve set up Git on your servers.
Which aliases do you rely on most, and do you allow gh logins on shared servers or stick to deploy keys? Feel free to post any errors in the comments.
If something didn’t work on your setup, leave a comment and tell me
which distro and version you’re on.
I read every one, and most of
these articles got better because a reader pointed out what was missing.
And if it did work, share it.
TecMint has stayed free for 14 years
because people pass these articles around, and that traffic is what
pays for writing the next one.
Learn the Linux basics with two free courses and join 34,000+ readers getting practical TecMint tutorials and selected Pro TecMint articles every week.
If you want to go beyond the free tutorials, Pro gives you
18 courses, 5 ebooks, and every future course I add.
One payment, lifetime access, no renewals.
—
**📚 Original Source:**
[5 Git and GitHub CLI Tips to Work Faster on Linux Servers](https://www.tecmint.com/git-github-cli-tips/)
