This content originally appeared on DEV Community and was authored by 100x.crypto ๐๐
If you use Ubuntu (or any Linux system) regularly, chances are you've customized it over time, adding handy aliases, defining environment variables, tweaking your shell prompt, and installing useful tools.
These small changes make your system feel yours. But here is the problem:
๐ก What happens if your system breaks, gets wiped, or you switch to a new machine?
If all your configuration lives only on one device, you could lose hours โ even days โ of work rebuilding your environment from scratch.
The solution: Store your configuration files ("dotfiles") in a GitHub repository.
This not only backs them up but also makes it easy to sync them across devices and restore your setup instantly on a new machine.
This guide shows you how to do exactly that, step by step.
๐ Step 1: Organize your config files
Let's say you would like to back up your ~/.bashrc
and ~/.bash_aliases
files (you can apply the same approach to any other config file).
First, create a dedicated folder within your home directory (~
) to hold your dotfiles:
mkdir ~/dotfiles
Now copy your config files into that folder:
cp ~/.bashrc ~/dotfiles/bashrc
cp ~/.bash_aliases ~/dotfiles/bash_aliases
๐ก Tip: To view your dotfiles in your home directory (hidden by default), use
ls -a
.
โ ๏ธ Security Warning:
Be very careful not to include sensitive files in your dotfiles repository โ especially if itโs public.
โ Never commit files like:
-
~/.ssh/*
(private SSH keys) -
~/.aws/credentials
(cloud access keys) -
.env
files with API keys or passwords - GPG keys or database credentials
If someone gains access to these files, they could impersonate you, access your servers, or compromise your accounts.
โ Best practice:
- Only track safe, reusable configuration files (like
.bashrc
,.bash_aliases
,.gitconfig
, etc.). - Add sensitive files to
.gitignore
so theyโre never pushed by mistake. - Consider using a private repository if you absolutely must store sensitive configs โ and even then, avoid committing secrets directly.
๐งฐ Step 2: Initialize a Git repository
Log in to your GitHub account in your browser and create a new repository called dotfiles
. Leave it empty (i.e., don't initialize with a README or .gitignore
). We'll add the files from our local machine shortly.
Now navigate to your newly created local dotfiles
folder via
cd ~/dotfiles
...and turn it into a Git repository:
git init
git add .
git commit -m "Initial backup of my shell config"
Your configuration files are now tracked by Git locally.
๐ก Note: If you don't have Git installed or run into issues here, check out my other post on how to install Git and push your first repository.
๐ Step 3: Push it to GitHub
Next, connect your local repository to the remote one you just created:
git remote add origin git@github.com:yourusername/dotfiles.git
Now push your local files to GitHub:
git branch -M main
git push -u origin main
If everything worked correctly, you should now see your bashrc
and bash_aliases
files listed in your GitHub repository.
๐งช Step 4: Restore your setup on a new machine
Hereโs where the magic happens. If you ever reinstall your OS or switch to a new device, you can bring your setup back with just a few commands:
git clone git@github.com:Walodja1987/dotfiles.git ~/dotfiles
cp ~/dotfiles/bashrc ~/.bashrc
cp ~/dotfiles/bash_aliases ~/.bash_aliases
source ~/.bashrc
Boom! Your terminal is back exactly how you left it.
๐ก Note on SSH vs HTTPS:
In the example above, I cloned the repo using the SSH URL (git@github.com:...
), which lets Git authenticate automatically using your SSH key, without a password or token.
Once your SSH key is configured on GitHub, this is usually the easiest option. Check out my other post no how to set up the SSH key.
If you prefer to use HTTPS, you can do so, but GitHub no longer accepts passwords for Git operations. Instead, you'll need to use a Personal Access Token (PAT) as your password when prompted (you find the PAT in GitHub under Settings -> Developer Settings -> Personal access tokens -> Tokens (classic)):
git clone https://github.com/yourusername/dotfiles.git ~/dotfiles
- Username: your GitHub username
- Password: your Personal Access Token (PAT)
Both methods work, but SSH is often smoother for day-to-day use, while HTTPS + PAT can be useful in scripts or CI/CD pipelines.
๐ง Step 5: Keep it up to date
Whenever you tweak your local dotfiles, just update your repository:
cp ~/.bash_aliases ~/dotfiles/bash_aliases
cp ~/.bashrc ~/dotfiles/bashrc
cd ~/dotfiles
git add .
git commit -m "Update aliases and bashrc"
git push
This ensures your GitHub repo always mirrors your current setup and your latest configuration is always just a git clone
away.
โจ Final Thoughts
Treating your shell configuration like code โ version-controlled, backed up, and portable โ is one of the most valuable habits you can develop as a developer or power user.
With a simple dotfiles repository on GitHub, your carefully crafted setup is safe, reproducible, and always within reach, no matter what happens to your system.
Note: I use ChatGPT to help me gather information and shape these posts, but I always test the commands myself and add my own insights to make them easier to understand. This blog is my personal record of what I learn as I go deeper into Linux. If it helps someone else too, even better!
This content originally appeared on DEV Community and was authored by 100x.crypto ๐๐

100x.crypto ๐๐ | Sciencx (2025-10-14T07:40:03+00:00) How to back up and sync your terminal configuration with a GitHub dotfiles repo. Retrieved from https://www.scien.cx/2025/10/14/how-to-back-up-and-sync-your-terminal-configuration-with-a-github-dotfiles-repo/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.