Fundamentals 46 min read

Comprehensive Git Tutorial: Installation, Basic Operations, Branching, and Collaboration

This extensive guide walks readers through Git fundamentals, covering Windows installation, core commands for repository creation, staging, committing, diffing, logging, resetting, branching, merging, remote synchronization, conflict resolution, stash usage, and best practices for collaborative development.

Code Ape Tech Column
Code Ape Tech Column
Code Ape Tech Column
Comprehensive Git Tutorial: Installation, Basic Operations, Branching, and Collaboration

Git is a distributed version control system that tracks changes in files and enables collaboration across multiple developers.

Installation on Windows can be done by downloading msysgit, running the default installer, and configuring your user name and email with git config --global user.name "Your Name" and git config --global user.email "[email protected]".

To start a repository, navigate to your project folder and run git init. Add files to the staging area with git add <file> or git add ., then commit them using git commit -m "Initial commit". Check the repository status with git status and view changes with git diff or git diff --cached.

History can be inspected via git log, optionally formatted with git log --pretty=oneline. To revert changes, use git reset --hard HEAD^ for the previous commit, or git reset --hard <commit-id> for a specific commit. The command git checkout -- <file> discards uncommitted modifications.

Branching is performed with git branch <branch-name> and switched with git checkout <branch-name> or combined via git checkout -b <branch-name>. Merge branches using git merge <branch>, and delete a branch with git branch -d <branch-name>. For non‑fast‑forward merges, add --no-ff to preserve branch history.

Remote repositories are added with git remote add origin https://github.com/username/repo.git. Push changes using git push origin <branch> (add -u on the first push) and pull updates with git pull origin <branch>. Clone an existing repository via git clone <url>.

When conflicts arise, resolve them manually in the affected files, then commit the resolution. The git stash command saves unfinished work, which can be reapplied later with git stash apply or git stash pop.

Overall, mastering these commands enables efficient version control, safe experimentation with branches, and smooth teamwork across distributed environments.

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.

Gitcommand-lineTutorialVersion ControlCollaborationbranching
Code Ape Tech Column
Written by

Code Ape Tech Column

Former Ant Group P8 engineer, pure technologist, sharing full‑stack Java, job interview and career advice through a column. Site: java-family.cn

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.