Getting Started with Git and GitHub: A Beginner's Guide
Source: Dev.to
Introduction
In the world of software development, version control is essential. Git is a version control tool that helps you track changes in your code, while GitHub allows for collaboration and showcases your projects. This guide walks through setting up Git Bash, connecting it to your GitHub account, and the basics of pushing and pulling code.
What is Git Bash?
Git Bash provides a Unix‑like terminal on Windows, giving you access to Git commands and common Bash utilities.
What is GitHub?
GitHub is a cloud‑based platform for hosting Git repositories, enabling collaboration, issue tracking, and project showcase.
Why Use Git and GitHub?
- Version Control – Track changes to your code over time.
- Collaboration – Work with others seamlessly.
- Portfolio – Showcase your projects to potential employers.
Installing Git Bash
- Select your operating system on the official Git website.
- Download and run the installer.
Verifying Installation
git --version
Configuring Name and Email
# Set your name
git config --global user.name "YourName"
# Set your email
git config --global user.email "YourEmail"
# Verify the configuration
git config --list
Connecting GitHub to Git Bash Using SSH Keys
Generate an SSH Key
# List existing keys (optional)
ls ~/.ssh
# Generate a new Ed25519 key
ssh-keygen -t ed25519 -C "YourEmail"
# Start the ssh-agent
eval "$(ssh-agent -s)"
# Add the private key to the agent
ssh-add ~/.ssh/id_ed25519
Add the SSH Key to GitHub
# Copy the public key to the clipboard (Windows)
clip < ~/.ssh/id_ed25519.pub
- Go to GitHub → Settings → SSH and GPG keys → New SSH key.
- Paste the copied public key, give it a title (e.g., “GitHub Key”), and click Add SSH key.
Test Your Connection
ssh -T git@github.com
You should see a success message confirming authentication.
Basic Git Commands
# Create a new directory and initialize a repository
mkdir kenya
cd kenya
git init
# Create files
touch nairobi
touch student.py
touch README.md
# Stage all changes
git add .
# (Optional) Return to home directory
cd ~
Conclusion
Mastering Git and Git Bash is essential for effective version control and collaboration in software development. By understanding these basic commands and configuring SSH authentication, you can efficiently manage your projects and contribute to others’ work on platforms like GitHub.