π How to Configure Git in Linux Terminal: Set Up Your Code Vault Like a Pro!


Hey fellow developers! π
Stepping into the world of version control can feel like entering a high-security vault for your precious code. Git β the widely adopted distributed version control system β is that vault, and your Linux terminal? Thatβs your personal control panel π§ π.
In this guide, weβll walk through:
Configuring Git on your Linux terminal
Creating a GitHub repository
Securing access using SSH keys π
Mastering core Git workflows
Think of this as setting up your digital fortress and learning how to safely store, retrieve, and share your code treasures π.
π§ Step 1: Meet Git β Your Codeβs Time Machine
Imagine writing a critical document and saving versions like final_final_v2_reallyfinal.docx
. Sounds familiar, right? π
Git is your time machine π°οΈ. It tracks every change, lets you rewind, compare, and collaborate without ever losing your precious code. It's the ultimate tool for avoiding chaos and restoring peace in your code universe π§ββοΈ.
π€ Step 2: Initial Configuration β Set Your Identity
Before using Git, tell it who you are. Itβs like registering your fingerprint and keycard for the digital vault.
git config --global user.name "Your Awesome Name"
git config --global user.email "your.email@example.com"
πΉ --global
ensures the settings apply across all repositories on your system.
To verify your config:
git config --list
β Done! Now Git knows whoβs behind the commits.
ποΈ Step 3: Create Your First Vault β Setting Up a GitHub Repo
Now letβs build your remote vault on GitHub:
Log in to GitHub.
Click β (top-right) β New repository.
Give it a name (e.g.,
my-first-repo
) and optionally a description.Choose public or private.
Skip README, .gitignore, license for now.
Click Create repository.
π GitHub will show you a repository URL β copy it, weβll need it soon!
π Step 4: Secure the Vault β Add SSH Key Authentication
Using SSH keys is like issuing yourself a secure digital keycard πͺͺ to access your vault without entering credentials every time.
π Check for Existing SSH Keys
ls -al ~/.ssh
Look for files like id_rsa
or id_ed25519
and their .pub
(public key) counterparts.
π§ Generate a New SSH Key (if needed)
ssh-keygen -t ed25519 -C "your.email@example.com"
Hit Enter to accept defaults, and optionally set a passphrase.
π Copy and Add SSH Key to GitHub
cat ~/.ssh/id_ed25519.pub
Copy the contents, then:
Go to GitHub β Settings β SSH and GPG keys
Click New SSH key
Give it a name, paste the key, and save
β Test the SSH Connection
ssh -T git@github.com
You should see:
"Hi username! Youβve successfully authenticated..."
π Step 5: Add and Push Your First File
Letβs place your first treasure in the vault!
1. Navigate to Your Project Folder
cd ~/projects/
mkdir my-first-repo
cd my-first-repo
2. Initialize Git Locally
git init
π οΈ Creates a hidden .git
directory.
3. Create a File
echo "This is my first file in the Git vault!" > my_first_file.txt
4. Stage Your Changes
git add my_first_file.txt
Or stage everything:
git add .
5. Commit the File
git commit -m "Added my first file"
π You just locked your first snapshot in the vault.
6. Link to GitHub
git remote add origin git@github.com:yourusername/my-first-repo.git
7. Push to Remote Vault
git push -u origin main
(If the default branch is master
, use that instead.)
π Head over to GitHub β your file should now be visible!
π§² Step 6: Retrieving Treasures β Clone & Pull
π§³ Clone a Repository
To copy a repo to your machine:
git clone git@github.com:yourusername/my-first-repo.git
π¬ Now youβve got a local vault copy with full history.
π Pull Updates
To get the latest from GitHub:
git pull origin main
π₯ Keeps your vault in sync with collaborators.
π§© Troubleshooting Common Git Gremlins
β error: src refspec main does not match any
You're trying to push a branch that doesn't exist. Use:
git push origin master
Or rename your branch:
git branch -m master main
π Permission denied (publickey)
Check your SSH setup:
ssh-add ~/.ssh/id_ed25519
Test again with:
ssh -T git@github.com
π fatal: remote origin already exists.
Reset the remote:
git remote set-url origin <new_url>
Check remotes with:
git remote -v
π₯· Pro Tips for Git Ninjas
π§Ύ Write Clear Commit Messages
Descriptive messages make history easy to understand.
π Use .gitignore
Keep clutter (e.g., node_modules
, .env
) out of your repo:
touch .gitignore
echo "node_modules/" >> .gitignore
π± Use Branches for Features
git checkout -b feature/new-login
Then:
git commit -m "Add login logic"
git checkout main
git merge feature/new-login
π Pull and Push Often
Avoid conflicts. Stay in sync.
π΅οΈ Explore Git Logs
git log --oneline --graph --all
πΎ Stash Changes Temporarily
git stash
Bring them back with:
git stash pop
πΌοΈ Try Visual Tools
Use GitKraken, Sourcetree, or your IDEβs Git view for complex tasks.
π Conclusion: Youβve Unlocked the Vault! π
π Congrats! Youβve just:
Configured Git
Created a GitHub repo
Set up SSH authentication
Made your first commit
Pushed code to GitHub
Learned how to pull and clone
Git might seem intimidating at first, but once you understand the vault metaphor, everything clicks π‘.
As you grow in your DevOps or development journey, Git will be your loyal companion in versioning, collaboration, and code safety. πͺ
Got questions or faced a weird Git issue? Drop a comment below or share your favorite Git tip! π
Happy coding ! π§βπ»π
Subscribe to my newsletter
Read articles from Santosh Nc directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Santosh Nc
Santosh Nc
I believe, "Hard work beats Talent when Talent doesn't work hard". A Technophile specialising in DevOps.Currently Employed at DevOps Engineer. Shaping my career with Jenkins,Docker, Automation,Poweshell, Python and other devops tools.