All of this revolves around Git and version control.
This article will walk you through:
*What Git is and why version control is important
*
- How to push code to GitHub
- How to pull code from GitHub
How to track changes using Git
What Is Git?
Git is a version control system.In simple terms, Git helps you:
- Keep track of changes in your code
- Go back to previous versions if something breaks
- Work with other developers without overwriting each other’s work
- Why Is Version Control Important? Version control solves these problems.
Benefits of Git & Version Control
- History tracking – See who changed what and when
- Backup – Your code is safely stored remotely
- Collaboration – Multiple people can work on the same project
- Undo mistakes – Easily revert to a previous version
- Branching – Work on new features without breaking the main code
What Is GitHub?
GitHub is a platform that hosts Git repositories online.
Git the tool (installed on your computer)
GitHub the service that stores your Git projects on the internetInstalling Git
Before using Git, install it:
Windows / macOS / Linux:
(https://git-scm.com/install/)
Verify installation:
git --version
- Basic Git Setup (One-Time)
Tell Git who you are:
`
git config --global user.name "Rose1845" // replace with your github username
git config --global user.email "odhiamborose466@gmail.com" // replace with your own email
`
- How to Push Code to GitHub Step 1: Create a Repository on GitHub
Go to https://github.com
Click New Repository
Give it a name
Click Create repository
Step 2: Initialize Git Locally
Inside your project folder:
git init
This creates a hidden .git folder that Git uses to track changes.
Step 3: Track Files
Check file status:
git status
Add files to Git:
git add .
Step 4: Commit Changes
A commit is a snapshot of your code at a specific point in time.
git commit -m "Initial commit"
Step 5: Connect to GitHub
Copy the repository URL from GitHub, then run:
git remote add origin https://github.com/username/repository-name.git
Step 6: Push to GitHub
git branch -M main
git push -u origin main
Your code is now on GitHub!
- How to Pull Code from GitHub Pulling means downloading the latest changes from GitHub. Clone a Repository (First Time)
git clone https://github.com/username/repository-name.git
This creates a local copy on your machine.
Pull Latest Changes
If you already cloned the repo:
git pull origin main(name of your branch in this case it's main)
- This Fetches new changes
- Merges them into your local code
- How to Track Changes Using Git Git gives you powerful tools to see what’s happening in your project. Check File Status
git status
This Shows:
- Modified files
- Staged files
- Untracked files
**See Changes in a File
git diff
- Shows what changed before committing. **View Commit History
- git log
THis Displays:
- Commit IDs
- Authors
- Dates
- Messages *Short Commit History *
git log --oneline
*Great for a quick overview
*
- A Typical Git Workflow Most follow this cycle:
- Make changes to code
- Check status
git status
Add changes
git add .
Commit changes
git commit -m "Describe what you changed"
Push to GitHub
git push
Top comments (0)