If you’ve just started learning web development or software engineering, chances are you’ve heard about Git. But what exactly is Git?

Git is a free and open-source version control system used by developers all over the world. It allows you to track changes in your code, collaborate with others, and work on large-scale projects without losing your progress. Git is especially powerful when paired with GitHub, a platform where you can store your code in the cloud and contribute to open-source projects.
Imagine you’re writing an assignment and want to save different versions before making final changes. Git helps you do that but for code.
Getting Started with Git: Basic Commands You Must Know
Before diving into real projects, you need to get familiar with a few foundational Git commands. Let’s look at them one by one:
git init
Initializes a new Git repository in your current folder. It’s like saying, “Hey Git, start tracking this folder.”
git init
git add .
Stages all the changes (added, modified, or deleted files) in your current directory.
git add .
git commit -m "Your message"
Commits the staged changes with a message that describes what changes you made.
git commit -m "Initial commit"
git branch -m main
Renames your current branch to main
. By default, it might be named master
.
git branch -m main
git remote add origin <repo_url>
Connects your local repository to a remote repository (for example, on GitHub).
git remote add origin https://github.com/your-username/your-repo.git
git remote -v
Shows the list of linked remote repositories with fetch and push URLs.
git remote -v
git push -u origin main
Pushes your main branch to the remote origin
, and sets the upstream for future pushes.
git push -u origin main
Git Branching Explained
Branching is one of the most powerful features of Git. It allows you to create separate versions of your code to work on new features or bug fixes without touching the main code.
git branch [branch_name]
Creates a new branch.
git branch feature-login
git branch
Lists all the available branches and shows which one you’re currently on.
git checkout [branch_name]
Switches to a different branch.
git checkout feature-login
git checkout -b [branch_name]
Creates and switches to a new branch in one command.
git checkout -b bugfix-header
git branch -d [branch_name]
Deletes a branch (only if it has been merged).
git branch -d old-feature
Step-by-Step Guide to Contributing to Open Source Projects
One of the most exciting uses of Git is contributing to open source. Let’s break down the full workflow in simple steps.
Step 1: Fork the Repository
- Visit the GitHub repository you want to contribute to.
- Click the Fork button at the top right.
- Choose your GitHub account.
- GitHub will create a forked copy in your account.
Step 2: Clone the Forked Repository
- Go to your forked repository on GitHub.
- Copy the repository link (HTTPS or SSH).
- Clone it to your local system:
git clone https://github.com/your-username/forked-repo.git
- Move into the cloned directory:
cd forked-repo
Step 3: Create a New Branch for Your Changes
git checkout -b feature-improve-readme
Or check branches using:
git branch
You can delete a branch later with:
git branch -d branch-name
Complete web development with Programming Hero
-৪৩০০+ জব প্লেসমেন্ট
– ৩ বেলা ডেডিকেটেড লাইভ সাপোর্ট
-১০০% জব প্লেসমেন্ট সাপোর্ট
-৮৫ টি মডিউল, ১২+ মাইলস্টোন
-ডেডিকেটেড হেল্প ডেস্ক ২৪/৭
Step 4: Make Changes and Push
- After editing files, stage them:
git add .
- Commit the changes with a message:
git commit -m "Improved README file"
- Push your branch to your forked GitHub repository:
git push origin feature-improve-readme
Step 5: Create a Pull Request (PR)
- Visit the original repository on GitHub.
- You’ll see an option like “Compare & pull request” click it.
- Write a short summary of your changes.
- Submit the PR and wait for the maintainer’s review.
- Done! 🎉 You’ve contributed to open source!
Other Handy Git Commands for Day-to-Day Use
git log
Shows a list of all commits along with author names and timestamps.
git log
git log --oneline
Displays commit history in a short format one commit per line.
git log --oneline
git reset --hard [commit_id]
Resets your code to a specific commit and discards all later changes. ⚠️ Be careful!
git reset --hard a1b2c3d
git push -f
Forcefully pushes your changes. Useful when rewriting commit history. Use with caution.
git push -f
git revert [commit_id]
Creates a new commit that undoes the changes of a previous commit, without affecting other commits.
git revert a1b2c3d
Learning Git might feel overwhelming at first, but once you start using it regularly, it becomes second nature. Whether you’re building your first personal project or contributing to a huge open-source repository, Git helps you stay organized and collaborative.
Start by remembering the basic commands shared in this guide, try creating branches, making commits, and exploring GitHub. Don’t just read practice!
Bonus Tip: You can use platforms like GitHub Desktop or VS Code Git integration to interact with Git in a more visual way.
For More Updateds Check