Fundamentals 42 min read

Master Git: From Basics to Advanced Workflows and Pro Tips

This comprehensive guide walks you through Git fundamentals—including its core concepts, installation, configuration, common commands, branching, merging, rebasing, tagging, stashing, cherry‑picking, remote workflows, and GUI tools—so you can confidently manage version control in any software project.

Architect's Guide
Architect's Guide
Architect's Guide
Master Git: From Basics to Advanced Workflows and Pro Tips

01. Getting Started with Git

Git is a free, open‑source distributed version‑control system that tracks every change to your code files, enabling you to revert to any previous state and collaborate across multiple developers.

Key Features

Open‑source and widely adopted

Full history snapshots (not just diffs)

Distributed workflow – most operations are local

Simple branch and merge model

02. Core Concepts

Workspace – the directory you see on your computer.

Index (Staging Area) – a hidden file .git/index that holds changes ready to be committed.

Repository – the .git folder that stores all commits, branches, tags, and configuration.

Remote – a server copy of the repository (e.g., GitHub, GitLab).

Basic Workflow

git add .          # stage all changes
git commit -m "msg" # create a new commit
git push origin main # upload to remote

03. Installing and Configuring Git

Download the installer from git-scm.com and run it. After installation you can verify the version with: git --version Configure your identity globally:

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

Set the default branch name (optional):

git config --global init.defaultBranch main

.gitignore

Create a .gitignore file in the repository root to exclude files such as logs, build artifacts, or private configuration. Example rules:

# ignore all .txt files
*.txt
# but keep lib.txt
!lib.txt
# ignore the temp folder at the root
/temp
# ignore everything under build/
build/

04. GUI Tools for Git

TortoiseGit – Windows Explorer integration.

Sourcetree – free cross‑platform client with visual branch management.

GitHub Desktop – official GitHub client.

GitKraken – advanced UI with paid features.

05. Working with Remotes

Two common authentication methods:

HTTPS – username/password (or token) in the URL.

SSH – public/private key pair; add the public key to your Git host.

Typical remote commands:

git remote -v                # list remotes
git remote add origin [email protected]:user/repo.git
git push origin main        # push local main to remote
git pull origin main        # fetch and merge remote changes

Fetching vs Pulling

git fetch

only updates remote tracking branches; git pull does a fetch followed by a merge (or rebase).

06. Branching

Create, switch, and delete branches with:

# list branches
git branch -a
# create a new branch
git branch feature-x
# switch to it (Git 2.23+)
git switch feature-x
# delete a branch
git branch -d feature-x

Merge a branch into the current one:

git merge dev               # fast‑forward if possible
git merge --no-ff dev      # create a merge commit

Rebase a branch onto another:

git checkout dev
git rebase main

07. Tags

Tags mark specific points (e.g., releases). Create an annotated tag: git tag -a v1.0 -m "Release 1.0" Push tags to the remote:

git push origin v1.0
# or push all tags
git push origin --tags

08. Undoing Changes

Discard uncommitted changes: git checkout . or git reset HEAD . Undo the last commit (keep changes): git reset --soft HEAD~1 Undo the last commit completely: git reset --hard HEAD~1 Revert a specific commit (creates a new commit):

git revert abc123

09. Stashing

Temporarily save uncommitted work:

git stash               # save and clean working tree
git stash list          # view saved stashes
git stash pop           # apply and remove the latest stash
git stash apply stash@{2} # apply without removing

10. Cherry‑Picking

Apply a single commit from another branch:

git checkout main
git cherry-pick abcdef   # copy commit abcdef onto main

11. Git Flow (Branching Model)

Typical long‑living branches:

master – production‑ready code.

develop – integration branch for features.

feature/* – individual feature development.

release/* – preparation for a new release.

hotfix/* – urgent fixes to production.

Workflow example:

# start a new feature
git checkout -b feature/login develop
# finish feature
git checkout develop
git merge feature/login
# create a release
git checkout -b release/1.1 develop
# after testing, merge into master and develop
git checkout master
git merge release/1.1
git tag -a v1.1 -m "Version 1.1"
git checkout develop
git merge release/1.1

12. Summary

Git provides a powerful, flexible system for tracking changes, collaborating across teams, and managing releases. Mastering its core concepts, commands, branching strategies, and auxiliary tools like stashing and cherry‑picking enables efficient, reliable software 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.

CLIGitVersion ControlbranchingMerging
Architect's Guide
Written by

Architect's Guide

Dedicated to sharing programmer-architect skills—Java backend, system, microservice, and distributed architectures—to help you become a senior architect.

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.