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

Santosh NcSantosh Nc
5 min read

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:

  1. Log in to GitHub.

  2. Click βž• (top-right) β†’ New repository.

  3. Give it a name (e.g., my-first-repo) and optionally a description.

  4. Choose public or private.

  5. Skip README, .gitignore, license for now.

  6. 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.

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 ! πŸ§‘β€πŸ’»πŸ”

0
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.