Introduction to Git and Github
Source: Dev.to
Why version control is important
- Every change is recorded
- You can go back to older versions of your code
- You can see who made a change and when
- Multiple developers can work on the same project safely
How to Track Changes Using Git
Step 1: Initialize Git
git init
This tells Git to start tracking the project.
Step 2: Check File Status
git status
Shows which files have changed.
Step 3: Add Files to Staging
git add .
The . adds all changed files.
Step 4: Commit Changes
git commit -m "Describe what you changed"
A commit is like saving a checkpoint in a game—you can always return to it later.
How to Push Code to GitHub
Step 1: Create a Repository on GitHub
- Go to GitHub.
- Create a new repository.
- Copy the repository URL.
Step 2: Connect Your Project to GitHub
git remote add origin
Step 3: Push Your Code
git push -u origin main
Your code is now stored on GitHub and accessible online.
How to Pull Code from GitHub
Pulling downloads the latest code from GitHub to your computer.
git pull origin main
Useful when:
- You are working on multiple computers.
- Other developers have made changes to the project.
Summary
- Git tracks changes in your files.
- Version control helps you manage and recover your code.
- GitHub stores your projects online.
- Push uploads your code to GitHub.
- Pull downloads updates from GitHub.
- Commits save your progress step by step.