Fundamentals 20 min read

Master Git: From Installation to Advanced Branch Management on Windows

This comprehensive guide walks you through installing Git on Windows, explains core concepts like the workspace, index, and repository, compares Git with SVN, and demonstrates essential commands for creating, committing, branching, merging, stashing, and collaborating with remote repositories, all illustrated with step‑by‑step screenshots.

Java Interview Crash Guide
Java Interview Crash Guide
Java Interview Crash Guide
Master Git: From Installation to Advanced Branch Management on Windows

What is Git?

Git is a modern distributed version control system. Its main components are the Workspace (working directory), the Index/Stage (staging area), the Repository (local .git directory), and Remote repositories.

SVN vs. Git

SVN is a centralized system requiring network access for most operations, while Git is distributed, allowing offline work and peer‑to‑peer collaboration.

Installing Git on Windows

Download the msysgit installer, run it with default options, and then open Git Bash from the Start menu. After installation, configure your identity:

git config --global user.name "Your Name"
git config --global user.email "[email protected]"

Basic Operations

Initialize a repository with git init. Add files to the staging area using git add <file>, then commit with git commit -m "message". Use git status to view changes and git diff <file> to see modifications.

Version Reverting

View history with git log (or git log --pretty=oneline). Revert to previous commits using git reset --hard HEAD^ (one step back) or git reset --hard HEAD~100 (100 steps back). Find specific commit hashes with git reflog and reset to them.

Working vs. Staging Areas

The working directory holds your current files; the staging area records snapshots to be committed. git add moves changes to the staging area, and git commit creates a new commit from the staged snapshot.

Creating and Merging Branches

Create a branch with git branch <name> or git checkout -b <name>, switch with git checkout <name>, and merge using git merge <branch>. Delete a branch with git branch -d <name>. Use --no-ff to force a merge commit.

Bug Branches and Stash

For urgent bug fixes, create a temporary branch (e.g., issue-404), fix the bug, merge back, and delete the branch. If you need to pause work, use git stash to save the current state, then restore with git stash apply or git stash pop.

Remote Repositories

Create an SSH key, add it to GitHub, then create a remote repository. Link the local repo with:

git remote add origin https://github.com/username/testgit.git

Push with git push -u origin master, pull with git pull, and fetch remote branches using git fetch. Set upstream branches with git branch --set-upstream-to=origin/dev dev.

Collaboration Workflow

When pushing fails due to remote updates, run git pull to merge remote changes, resolve any conflicts, commit, and push again. Use git checkout -b dev origin/dev to create local tracking branches for collaborative development.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

GitWindowsVersion Controlbranchingremote repository
Java Interview Crash Guide
Written by

Java Interview Crash Guide

Dedicated to sharing Java interview Q&A; follow and reply "java" to receive a free premium Java interview guide.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.