Comprehensive Guide to Git Installation, Configuration, and Common Workflow Commands
This article provides a detailed overview of Git as a distributed version control system, covering installation on Windows, global user configuration, core concepts such as working directory, repository, staging area and HEAD, typical branching workflows, remote repository setup, and a collection of frequently used Git commands.
Git is an open‑source distributed version control system that differs from centralized systems like SVN; each developer has a complete repository locally, allowing work without network access, while remote hosting services such as GitHub or GitLab provide a shared central point for collaboration.
Installation on Windows is straightforward: after running the installer, open "Git Bash" from the Start menu to verify a successful setup.
Configure your identity globally so that each commit records the author:
$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"Key concepts:
Working directory : the folder containing your project files; changes here are tracked by Git.
Repository (.git) : the hidden directory that stores all history, including the index (staging area) and the default master branch.
Staging area (index) : an intermediate area where you place changes before committing.
HEAD : a pointer to the current branch tip; switching branches moves HEAD.
Typical single‑developer workflow (Scenario 1): create a dev branch, develop, stage changes with git add, commit, then merge back to master:
git branch dev // create dev branch
git checkout dev // switch to dev
# develop …
git add filename
git commit -m "New feature"
git checkout master
git merge devWhen an urgent bug arises (Scenario 2), you can create a bugfix branch from master, fix the issue, merge it back, then resume work on dev and finally merge dev into master, handling any conflicts that appear.
To enable multi‑location collaboration, create a remote repository on GitHub/GitLab and link it:
git remote add origin https://example.com/yourrepo.git
git push origin master // push local master
# later
git push origin dev // push dev branchCloning to another machine and continuing development:
git clone https://example.com/yourrepo.git
git checkout -b dev origin/dev
# develop …
git add .
git commit -m "Feature"
git push origin devWhen pulling updates, Git performs a fetch followed by a merge; conflicts must be resolved manually before committing.
Commonly used commands (summarized): git init – initialize a repository. git add <file> – stage changes. git commit -m "msg" – commit staged changes. git push origin <branch> – push to remote. git pull – fetch and merge remote changes. git branch, git checkout, git merge – branch management. git diff, git diff --cached, git diff HEAD – view differences. git log – view commit history. git status – show repository status. git reset --hard <commit_id> – revert to a specific commit. git stash, git stash pop – temporarily store uncommitted changes.
References include the Liaoxuefeng Git tutorial and the official Git command manual.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
360 Quality & Efficiency
360 Quality & Efficiency focuses on seamlessly integrating quality and efficiency in R&D, sharing 360’s internal best practices with industry peers to foster collaboration among Chinese enterprises and drive greater efficiency value.
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.
