When a website goes live, it often undergoes updates—like adding an "About" page or a "Services" section later. Each of these updates is called a version, and GitHub helps you maintain a record of all these changes.
What is Git? And Why is it Important?
Git is a version control system that:
Tracks every change in your project.
Lets you revert to any previous version.
Helps developers collaborate and manage code efficiently.
How to Install Git?
Before using Git, you need to install it:
Download Git from git-scm.com.
Configure Git after installation:
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
You’re now ready to use Git!
Basic Git Commands
Initialize a new Git repository
git init
Check project status
git status
Track changes & commit them
git add .
git commit -m "First commit"
-m
means message.
Now, your project is being tracked by Git!
What is GitHub? How to Connect Git with GitHub?
GitHub is an online platform to store and share Git repositories.
Steps to connect Git with GitHub
Create a GitHub account.
Create a new repository.
Link Git to GitHub:
git remote add origin https://github.com/your-username/repo-name.git
git push -u origin main
Your project is now live on GitHub!
Git Branching – What is it & Why is it Important?
Branching allows you to work on new features without affecting the main code.
Create a new branch:
git branch feature-branch
Switch to a branch:
git checkout feature-branch
Create & switch in one command:
git checkout -b new-feature
Branching is crucial for teamwork!
Merging Branches – Combining Code
Once a feature is complete, merge it into the main branch:
Switch to the main branch:
git checkout main
Merge the branch:
git merge feature-branch
How to Handle Merge Conflicts?
If two people edit the same file, a merge conflict occurs.
Steps to Resolve Merge Conflicts:
Open the conflicting file.
Manually edit the correct code.
Save the file and commit changes.
Pushing & Pulling Code (Staying Updated with GitHub)
To fetch the latest updates from GitHub:
git pull origin main
To push your updated code to GitHub:
git push origin main
Bonus Tip: To download someone else’s GitHub project, use:
git clone repo-url