Git Version Control: Concepts, Commands, and Workflows
This article provides a comprehensive introduction to Git version control, covering its core concepts, key features, essential commands, various workflows such as Centralized, Feature Branch, Gitflow, and Forking, and practical tips for collaboration and history management.
This article is a detailed guide to Git version control and its workflows, aimed at readers who are new to Git or want to deepen their understanding of its concepts and commands.
What is Git?
Git is a distributed version control system. Unlike centralized systems such as SVN, Git stores a full copy of the repository on each client, allowing work to continue even if the central server fails.
Why use Git?
Provides file versioning and multi‑person collaborative development.
Powerful branching enables flexible workflows.
Distributed nature lets developers commit locally when the server is down.
Pull‑request workflow supports code review before merging.
Key Git Features
Three file states: modified, staged, committed.
Snapshots are recorded instead of diffs.
Most operations are local.
Data integrity is continuously verified.
Basic Git Workflow
Modify a file in a Git‑tracked directory.
Stage the changes with git add.
Commit the snapshot with git commit.
Useful Git Tricks
Auto‑completion.
Command aliases.
Common Commands
Initialize a repository: git init Clone a repository: git clone Configure user info: git config Stage changes: git add Commit changes: git commit Check status: git status View log: git log --oneline Undo changes: git checkout <commit> <file>, git checkout <commit>, git checkout <branch> Revert public commits: git revert <commit> Reset local changes: git reset, git clean Rewrite history: git commit --amend, git rebase,
git reflogCollaboration Commands
Branch management: git branch, git checkout, git merge Remote synchronization: git remote, git fetch, git pull,
git pushGit Workflows
Four common workflows are described, each suited to different team sizes and needs.
Centralized Workflow : Use a single remote repository, clone, commit locally, fetch/rebase, then push.
Feature Branch Workflow : Create a new branch for each feature, push the branch, open a pull request, and merge after review.
Gitflow Workflow : Employ dedicated branches for features, releases, and maintenance, with master for production and develop for integration.
Forking Workflow : Each contributor forks the central repository, works on their own fork, and submits pull requests to the upstream project.
Tagging Releases
Mark a release on the master branch with:
git tag -a 0.1 -m "Initial public release" master git push origin master --tagsFurther Reading
Pro Git (Chinese edition)
Atlassian Git Tutorials
Qunar Tech Salon
Qunar Tech Salon is a learning and exchange platform for Qunar engineers and industry peers. We share cutting-edge technology trends and topics, providing a free platform for mid-to-senior technical professionals to exchange and learn.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
