If you're just starting your developer journey, learning Git and Github is one of the best decisions you can make.
In this article, i'll show you how to set up Git, configure it with your name & email and connect it securely to GitHub using SSH.
What is Git?
Git is a version control tool that runs locally on your computer.
It let's you;
-Track file changes
-Create 'checkpoints' called commits
-Work on branches (separate copy) without affecting the main project
What is GitHub
GitHub is a cloud platform where you can store your Git repositories online, share them with others and collaborate on projects.
It let's you;
-Upload your code(push)
-Download updates(pull)
-Work together with others in real time
1.Setting up Git
How to install and configure Git.
For Windows
Download Git (Install for Windows)
Run the installer and choose "Git default editor" as your terminal
Once installed, open Git Bash and type:
git --version
You should see something like:
git version 2.xx.x
For macOS
Open terminal and run:
git --version
If Git isn't installed, macOS will prompt you to install it via Xcode tools.
For Linux (Ubuntu/Debian)
Run:
sudo apt update
sudo apt install git
2.Configure your Git identity
Before you start using Git, tell it who you are by using your name and email which you used to create your GitHub account.
Run these commands replacing with your details:
git config --global user.name "Your Name"
git config --global user.email "Your Email"
To confirm your details:
git config --global --list
3.Connecting Git to GitHub Using SSH Keys
SSH(Secure Shell) Keys let you connect to GitHub without typing your password every time.
How to set up:
(i).Generate a New SSH key
ssh-keygen -t ed25519 -C "Your Email"
Press Enter to save it in the default path.
(ii).Generate SSH Agent
eval "$(ssh-agent -s)"
(iii).Add Key to the Agent
ssh-add ~/.ssh/id_ed25519
(iv).Copy your Public Key
cat ~/.ssh.id_ed25519.pub
Copy the whole key that starts with
ssh-ed25519
(v).Add the Key to GitHub
1.Go to GitHub → Settings → SSH and GPG keys
2.Click New SSH key
3.Paste your copied key
4.Save it
(vi).Test the Connection
ssh -T git@github.com
If you see:
Hi yourusername! You've successfully authenticated.
You're all set.
4.Using Version Control with Git
Initialize a Repository
Go to your project folder and intialize Git:
git init
This creates a hidden .gitfolder.
Track changes
Check what's changed:
git status
Add files to be tracked:
git add.
Commit (save) the changes:
git commit -m "Initial commit"
Push code to GitHub
1.Create a new repository on GitHub
2.Copy the repo's SSH url
3.Connect it to your local repo:
git remote add origin git@github.com:username/repo.git
4.Push your code:
git push -u origin main
Now your project is on GitHub.
Pull updates from GitHub
When you make changes on GitHub, pull them locally:
git pull origin main
See your commit history
To view your project's history:
git log
To see a short summary:
git log --oneline
Top comments (0)