14 Git Commands You’ll Use 99% of the Time
This guide lists the 14 Git commands that cover 99% of everyday development tasks, explains each command’s purpose, provides example usage such as initializing a repository, cloning, adding, committing, pushing, pulling, branching, merging, checking status, rebasing, stashing, and reverting, and even shows a simple shell script for summarizing repository information.
Learning these 14 Git commands will cover the vast majority of daily development work.
1. git init – Initializes a new Git repository by creating a .git directory that stores all metadata.
2. git clone – Clones an existing repository, creating a local copy with full history and branches. Example: git clone <repo‑url>.
3. git add – Adds specified files to the staging area for the next commit. Example: git add file1.txt file2.txt.
4. git commit – Creates a new commit that records the staged changes along with a descriptive message. Example: git commit -m "Add new feature".
5. git push – Pushes local commits to a remote repository, updating the remote branch. Example: git push origin main.
6. git pull – Fetches the latest commits from a remote repository and merges them into the current branch. Example: git pull origin main.
7. git branch – Lists, creates, or deletes branches. Example to create a branch: git branch new-branch.
8. git checkout – Switches to a different branch, making it the current working branch. Example: git checkout main.
9. git merge – Merges changes from one branch into another, creating a new commit that reflects the merge. Example: git merge new-branch.
10. git status – Shows the repository’s current state, including staged, unstaged, and untracked files. Example: git status.
11. git rebase – Reapplies commits from one branch onto another, effectively moving the base of the branch. For instance, rebasing a feature branch onto main after new commits have been added.
12. git stash – Temporarily saves uncommitted changes so you can switch branches without losing work.
13. git revert – Creates a new commit that undoes changes introduced by a previous commit. Example: git revert <commit1>..<commit2>.
These commands constitute the most frequently used Git operations and mastering them greatly improves development efficiency.
The article also shows a simple shell script (e.g., git_analysis.sh) that, when executed, displays the total number of commits, lists all branches, and shows the latest commit on each branch. Save the script with executable permission and run it from the command line to obtain a quick repository overview.
Linux Tech Enthusiast
Focused on sharing practical Linux technology content, covering Linux fundamentals, applications, tools, as well as databases, operating systems, network security, and other technical knowledge.
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.
