Master Git Basics: From Installation to Advanced Workflows
This guide walks beginners through Git fundamentals, covering installation, configuration, core commands, IDE integration, common workflows, and advanced operations like rebasing, resetting, and handling detached HEAD states, empowering developers to use version control confidently.
When first learning Git, even simple tasks like merging can feel intimidating, and mistakes such as entering a detached HEAD state can leave developers unsure of how to recover.
1. What is Git?
Git is an open‑source distributed version control system that records each commit as a snapshot of the project files.
2. Configuring Git Locally
git --versionCheck the installed version (e.g., git version 2.30.1 (Apple Git-130)). Then set global user information:
git config --global user.name 'zhengxing' git config --global user.email '[email protected]' git config -l # view configuration
3. Using Git in an IDE
IntelliJ IDEA integrates Git seamlessly, allowing you to manage repositories, commit, push, and interact with remote services like Gitee or GitLab without using the command line.
Git servers typically use SSH authentication; generate a public/private key pair, add the public key to the server, and use the private key locally for password‑less operations.
4. Common Git Operations in Projects
The typical workflow is Add → Commit → Pull → Push . Initialize a repository with git init, then use the following basic commands:
Add: git add . adds new files to the staging area ( .git/index).
Commit: git commit -m "message" records staged changes.
Pull: git pull updates the local working directory from the remote.
Push: git push uploads local commits to the remote branch.
Full operation steps example: 1. Create a new branch → Commit → Push. 2. Switch branches: click a branch → Checkout. 3. Change remote URL: Git → Manage Remotes…. 4. Merge into current branch: select branch → Merge into Current.
5. Advanced Commands
git status : shows untracked files and changes not staged for commit.
git init : creates a new repository.
git -c core.quotepath=false -c log.showSignature=false initgit commit --amend : modifies the most recent commit without creating a new one.
git reflog : displays the reference log of HEAD movements, useful for recovering lost commits (e.g., git reset HEAD@{1}).
git reset and git revert :
git checkout : switch branches or restore files; git checkout -b <branch> creates a new branch from a detached commit.
Detached HEAD : when HEAD points directly to a commit instead of a branch. Resolve by creating a temporary branch: git checkout -b <branch name>, then merge back.
6. Git Workflows
Workflows are collaborative conventions, not technologies. Common models include:
Centralized workflow : a single master branch shared by all developers.
Feature‑branch workflow : master (production) and develop (integration) branches, with feature branches created from develop. Changes are merged via Merge Requests or Pull Requests after code review.
Code Review ensures code quality before merging into protected branches.
7. Conclusion
The article summarizes essential Git concepts and commands, providing a foundation for developers to work confidently with version control.
Lin is Dream
Sharing Java developer knowledge, practical articles, and continuous insights into computer engineering.
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.
