Git and GitHub

INTRODUCTION
Git is an open source version control system used to track changes in our code projects and files. It keeps a track of what things we added , what things we deleted and what are the things we edited at different save checkpoints. On the other hand , GitHub is a platform where different people can collaborate to work on a single project. One main user can upload a project at its initial stage on GitHub and can add other people to collaborate on that project. The other people can create branches of that project which is like the copy of the project and can show different modifications on that project to the main user. If the main user wants, he can merge that changes with the main branch. GitHub is also used by big companies to make different groups work on different parts of a big project. The difference between Git and GitHub is that Git is a local repository while GitHub is a cloud based repository.
USES OF GIT AND GITHUB
1. Version Control
Track every change in your code base over time.
Go back to any previous version of your project.
2. Branching and Merging
Work on new features in isolated branches.
Merge them into the main project after testing.
3. Code Experimentation
Safely test new ideas without affecting the main code.
Use branches to try, fail, and learn.
4. Team Collaboration
- Multiple developers can work on the same project without overwriting each other’s code.
5. Error Recovery
- Undo mistakes using commands like
revert
,reset
, orcheckout
.
6. Audit and Debugging
- Use the commit history to see who changed what and why.
7. Remote Repository Hosting
Store your code securely in the cloud.
Access it from anywhere.
8. Team Collaboration and Code Review
Use pull requests for reviewing and merging code.
Add comments, suggest changes, and approve contributions.
9. Issue Tracking
- Report, assign, and track bugs or tasks within the project.
10. Open-Source Contribution
Fork popular projects, contribute code, and make pull requests.
Build a public developer profile.
11. Project Management
- Use GitHub Projects or Issues to manage features, tasks, and milestones.
12. CI/CD Automation with GitHub Actions
- Automate testing, building, and deployment processes.
13. Documentation and Hosting
Host wikis and project documentation.
Use GitHub Pages to host static websites or blogs.
COMMON STEPS TO SET UP A PROJECT ON GITHUB AND COLLABORATE WITH OTHER PEOPLE TO WORK ON IT
1. Create a New Repository on GitHub
Go to https://github.com
Click "New" or "+" → New repository
Fill in:
Repository name
Description (optional but helpful)
Choose public or private
Click "Create repository"
2. Set Up the Local Project
If you already have code:
bashCopyEditcd your-project-directory
git init
git remote add origin git@github.com:yourusername/repo-name.git
git add .
git commit -m "Initial commit"
git push -u origin main
Use SSH or HTTPS depending on your GitHub setup.
3. Add Collaborators (Team Members)
Go to the repo on GitHub
Click "Settings" → "Collaborators"
Invite people by GitHub username or email
They’ll receive an email to accept the invitation
4. Workflow for Collaborators
Clone the Repository:
bashCopyEditgit clone git@github.com:username/repo-name.git
Create a New Branch:
bashCopyEditgit checkout -b feature/your-feature
Make Changes, Then:
bashCopyEditgit add .
git commit -m "Added new feature"
git push origin feature/your-feature
5. Create a Pull Request (PR)
Go to the repository on GitHub
GitHub will detect new branches → click "Compare & Pull Request"
Add a title and description
Click "Create pull request"
Teammates can review, discuss, and approve the PR before merging.
6. Merge Pull Requests into main
Once reviewed:
Click “Merge pull request”
Delete the feature branch (optional but clean)
SOME OF THE MOST USEFUL GIT COMMANDS
1. git init
Initializes a new Git repository in your project folder.
bashCopyEditgit init
2. git clone <repository-url>
Downloads (clones) an existing repository from GitHub or another host to your local machine.
bashCopyEditgit clone https://github.com/user/repo.git
3. git status
Shows the current status of your working directory and staging area (what’s changed, staged, or untracked).
bashCopyEditgit status
4. git add <file>
or git add .
Stages file(s) to be committed.
bashCopyEditgit add index.html
git add . # Adds all changed files
5. git commit -m "message"
Records (commits) staged changes with a message describing the change.
bashCopyEditgit commit -m "Fixed login bug"
6. git push origin <branch-name>
Pushes your local commits to the remote repository (e.g., GitHub).
bashCopyEditgit push origin main
7. git pull
Fetches and merges changes from the remote repo to your local branch.
bashCopyEditgit pull
8. git checkout <branch or commit>
Switches to another branch or previous commit.
bashCopyEditgit checkout feature/login
9. git log
Shows a history of commits in the current branch.
bashCopyEditgit log
10. git branch
Lists all branches or creates a new one.
bashCopyEditgit branch # List
git branch new-branch # Create
MERGING IN GIT AND GITHUB
Merging is the process of combining changes from one branch (e.g., feature-branch
) into another (usually main
or master
). This is a fundamental part of collaborative development, allowing multiple people to work on different parts of a project and later integrate their work.
Part 1: Merging in Git (Local)
Common Syntax:
bashCopyEditgit checkout main
git merge feature-branch
This does the following:
Switches to the
main
branch.Merges the
feature-branch
intomain
.
Fast-Forward Merge
This occurs when:
The
main
branch hasn't moved since thefeature-branch
was created.Git just moves the pointer of
main
forward to match thefeature-branch
.
bashCopyEdito---o---o <- main, feature
3-Way Merge
This happens when:
main
has new commits after thefeature-branch
was created.Git compares the common ancestor,
main
, andfeature-branch
to create a new merge commit.
bashCopyEdit A---B---C feature
/
o---o---o---M main (merge commit)
Merge Conflicts
If both branches changed the same line or file, Git can't merge automatically. You'll get a merge conflict that must be resolved manually:
bashCopyEdit<<<<<<< HEAD
code from main
=======
code from feature
>>>>>>> feature
After fixing:
bashCopyEditgit add .
git commit
Part 2: Merging in GitHub (Remote via Pull Request)
Collaboration via Pull Request (PR)
A developer pushes a branch to GitHub.
Opens a Pull Request (PR) to merge changes into
main
.Reviewers comment, approve, or request changes.
Once approved, the PR is merged via GitHub UI.
Merge Options on GitHub:
Option | Description |
Merge Commit | Default. Combines the branches and creates a merge commit. Preserves full history. |
Squash and Merge | Combines all commits into one before merging. Great for keeping history clean. |
Rebase and Merge | Applies each commit from the feature branch onto the base branch linearly. History appears cleaner but can rewrite commit history. |
CONCLUSION
To sum it up, Git and GitHub are really useful tools for anyone working with code. Git helps keep track of changes in your project, while GitHub makes it easier to work with others by sharing your code online. These tools are not just for big companies—students, beginners, and professionals all use them. Learning how to use Git and GitHub properly can really improve the way you manage your projects and collaborate with others. It might seem confusing at first, but once you get used to the basic commands and workflow, it becomes a habit. Over time, you’ll see how much easier it makes coding and teamwork
Subscribe to my newsletter
Read articles from RAHAT SHARMA directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
