Roadmap: Mastering Git in 2025
Git is an indispensable tool for version control and collaboration in software development. Git, a distributed version control system, allows you to track changes, manage different versions of your codebase, and work on multiple features simultaneously
. It helps maintain a complete history of your project and enables seamless integration of contributions from different developers. To get started, install Git, configure it, and initialize a repository. Clone it locally, make changes, commit them, and push updates to a remote repository. By leveraging branching, merging, and pull requests, you can efficiently collaborate with others and maintain a seamless development workflow.
Learning RoadMap
Introduction
Learn the basics: repositories, commits, branches, and clones.
Setting Up Your Environment
Installing Git
- Windows: Download and install from the Git official website.
- macOS: Use Homebrew:
//[title="src/script.sh"] brew install git
- Linux: Install via package manager, e.g.,
//[title="src/script.sh"] sudo apt-get install git
Configuring Git
Set your username and email:
//[title="src/script.sh"]
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
Core Concepts
Repositories
A repository is a storage space for your project. Initialize a new repository:
//[title="src/script.sh"]
git init
Commits
A commit records changes to the repository. Stage and commit changes:
//[title="src/script.sh"]
git add .
git commit -m "Your commit message"
Branches
Branches allow you to work on different versions of a project simultaneously. Create and switch to a new branch:
//[title="src/script.sh"]
git branch new-feature
git checkout new-feature
Cloning
Cloning creates a local copy of a remote repository:
//[title="src/script.sh"]
git clone https://github.com/username/repository.git
Working with Remote Repositories
Pushing Changes
After committing, push your changes to a remote repository:
//[title="src/script.sh"]
git push origin branch-name
Pulling Changes
Update your local repository with changes from the remote:
//[title="src/script.sh"]
git pull origin branch-name
Collaboration
Forking and Pull Requests
- Forking: Create your own copy of someone else's repository on GitHub.
- Pull Requests: Propose changes to the original repository.
Advanced Topics
Merging and Rebasing
- Merging: Combine changes from different branches.
- Rebasing: Reapply commits on top of another base tip.
Resolving Conflicts
When conflicts occur during merges:
//[title="src/script.sh"]
# Edit the conflicted files to resolve issues
git add resolved-file
git commit
Branching & Merging
{{youtube:XX-Kct0PfFc}}
Master feature branches, merging, and rebasing.
Why Use Branches?
Branches allow developers to work on new features or bug fixes independently without affecting the main
branch.
Common branching strategies include:
- Feature branches: For developing new features.
- Hotfix branches: For urgent fixes in production.
- Release branches: For preparing stable releases.
To create and switch to a new branch:
//[title="src/script.sh"]
git checkout -b feature-branch
Merging: Combining Changes
When a branch is ready, it must be merged back into main
.
- Fast-forward merge: Used when
main
has not changed since branching. - Three-way merge: Needed when both
main
and the branch have new commits.
Merge a branch into main
:
//[title="src/script.sh"]
git checkout main
git merge feature-branch
If unnecessary commits appear, consider a squash merge to combine them into a single commit.
Rebasing: Keeping a Linear History
Instead of merging, rebasing moves your branch on top of the latest main
changes, keeping history cleaner.
//[title="src/script.sh"]
git checkout feature-branch
git rebase main
If conflicts occur, resolve them, then:
//[title="src/script.sh"]
git add resolved-file
git rebase --continue
⚠️ Caution: Avoid rebasing branches that others are working on, as it rewrites commit history.
Cleaning Up Branches
Once merged, delete a branch locally:
//[title="src/script.sh"]
git branch -d feature-branch
And remotely:
//[title="src/script.sh"]
git push origin --delete feature-branch
Collaboration with Git
{{youtube:MnUd31TvBoU}}
Work with remotes, forks, pull requests, and reviews.
Working with Remote Repositories
A remote repository allows multiple developers to collaborate on the same project.
To link a local project to a remote repository (e.g., on GitHub or GitLab), add a remote URL:
//[title="src/script.sh"]
git remote add origin https://github.com/user/repo.git
Fetch the latest changes before starting new work:
//[title="src/script.sh"]
git pull origin main
Push your local commits to the remote repository:
//[title="src/script.sh"]
git push origin branch-name
Forking a Repository
A fork is a copy of someone else’s repository in your own account, allowing you to modify it independently.
After forking, clone the repository to your local machine:
//[title="src/script.sh"]
git clone https://github.com/your-username/forked-repo.git
Sync with the original repository to get updates:
//[title="src/script.sh"]
git remote add upstream https://github.com/original-owner/repo.git
git fetch upstream
git merge upstream/main
Pull Requests: Contributing to a Project
Once changes are made in your fork, submit a pull request (PR) to propose merging them into the original project.
Best practices for PRs:
- Keep changes focused and small.
- Write a clear description explaining your changes.
- Request a code review from maintainers.
Code Reviews and Collaboration
Reviews ensure code quality and catch potential issues before merging.
When reviewing PRs:
✅ Check for clarity, efficiency, and security.
✅ Suggest improvements via comments.
✅ Approve or request changes before merging.
Advanced Git
{{youtube:qsTthZi23VE}}
Learn interactive rebase, cherry-picking, and bisect.
Interactive Rebase: Rewriting History
Interactive rebase lets you modify, reorder, squash, or edit commits to maintain a clean history.
Start an interactive rebase for the last 5 commits:
//[title="src/script.sh"]
git rebase -i HEAD~5
You'll see a list of commits in your editor. Change pick
to:
reword
→ Edit commit messagesquash
→ Merge commit with the previous oneedit
→ Modify the commit
Once done, save and continue:
//[title="src/script.sh"]
git rebase --continue
⚠️ Warning: Avoid rewriting history on shared branches!
Cherry-Picking: Selectively Apply Commits
Cherry-picking allows you to apply a specific commit from one branch to another.
Find the commit hash (git log
or git reflog
), then:
//[title="src/script.sh"]
git cherry-pick <commit-hash>
This is useful when you need only certain changes from another branch.
Git Bisect: Debugging with Binary Search
When a bug appears, git bisect
helps find the exact commit that introduced it using binary search.
Start bisecting:
//[title="src/script.sh"]
git bisect start
git bisect bad # Mark the current (buggy) commit
git bisect good <commit-hash> # Mark a known good commit
Git will check out a middle commit—test if the bug exists and mark it:
//[title="src/script.sh"]
git bisect good # If the bug isn’t present
git bisect bad # If the bug is present
Repeat until Git finds the problematic commit. Then reset:
//[title="src/script.sh"]
git bisect reset
Handling Git Issues
{{youtube:QSpWI4qKFcc}}
Solve conflicts, recover lost commits, and use reflog.
Solving Merge Conflicts
Merge conflicts happen when Git can’t automatically combine changes from different branches.
When a conflict occurs, Git marks the problematic files. Open them and look for conflict markers (<<<<<<<
, =======
, >>>>>>>
).
- Manually edit the file to keep the correct changes.
- Stage the resolved file:
//[title="src/script.sh"]
git add resolved-file
- Complete the merge:
//[title="src/script.sh"]
git commit -m "Resolved merge conflict"
To abort a merge if things go wrong:
//[title="src/script.sh"]
git merge --abort
Recovering Lost Commits
If you accidentally lose commits (e.g., through a hard reset), use git reflog
to find them:
//[title="src/script.sh"]
git reflog
This shows a history of all branch movements. To restore a lost commit:
//[title="src/script.sh"]
git checkout <commit-hash>
Or reset the branch to an earlier state:
//[title="src/script.sh"]
git reset --hard <commit-hash>
Undoing Mistakes
- Undo last commit (keep changes unstaged):
//[title="src/script.sh"]
git reset HEAD~1
- Undo last commit (discard changes permanently):
//[title="src/script.sh"]
git reset --hard HEAD~1
- Restore a deleted file:
//[title="src/script.sh"]
git checkout HEAD -- path/to/file
Take a break!
Remember that git is one of those things that you have to know as well as speak your native language, use it daily!