Fundamentals 41 min read

Comprehensive Introduction to Git and Version Control Practices

This article provides a thorough introduction to Git, covering its core concepts, repository structure, essential commands for initialization, configuration, branching, merging, rebasing, remote operations, and troubleshooting, along with practical examples and visual diagrams to help developers master version control.

Top Architect
Top Architect
Top Architect
Comprehensive Introduction to Git and Version Control Practices

Git is a distributed version control system that records every change to files, enabling collaborative development and easy rollback. It organizes work into three areas: the working directory, the staging area, and the repository (.git folder).

The basic workflow includes initializing a repository with git init or cloning an existing one with git clone <url> , adding changes to the staging area using git add , and committing them to the repository with git commit -m "message" . Common commands such as git status , git log , git diff , git push , and git pull are explained with examples.

Configuration files are stored at three levels: system ( /etc/gitconfig ), user ( ~/.gitconfig ), and repository ( .git/config ). The .gitignore file controls which files are excluded from version control.

# Example: view global configuration
git config --global --list

Git supports both HTTPS and SSH authentication for remote repositories. SSH keys are generated with ssh-keygen -t rsa and added to services like GitHub.

# Generate SSH key pair
ssh-keygen -t rsa -b 4096 -C "[email protected]"

Branching is a lightweight operation that creates a new pointer to a commit. Commands such as git branch , git checkout -b <branch> , and git switch <branch> manage branches. Merging can be fast‑forward or create a merge commit; conflicts are marked with <<<<<<< HEAD markers for manual resolution.

Rebasing rewrites history to produce a linear commit sequence, useful for keeping feature branches up to date before merging.

# Rebase feature branch onto master
git checkout feature
git rebase master

Tags mark specific points in history, often used for releases. They are created with git tag -a v1.0 -m "release 1.0" and pushed using git push origin --tags .

Undoing changes can be done with git checkout . (unstaged files), git reset (unstage or move HEAD), git revert (create a new commit that undoes a previous one), and git reset --hard (discard all local changes).

The stash feature temporarily saves uncommitted work with git stash , allowing a clean switch to another branch. It can be reapplied with git stash pop or git stash apply .

Cherry‑pick copies a specific commit from another branch without merging the whole branch, using git cherry-pick <commit> .

Finally, the article outlines a typical Git workflow (Git Flow) with main, develop, release, and hotfix branches, illustrating how teams manage feature development, releases, and emergency fixes.

CLIgitrebaseVersion ControlRemotebranchingmerging
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

login 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.