Git Commands You Should Know as a Beginner Developer

Ever stared at your terminal wondering which git command to use next? You’re not alone. Git commands form the backbone of modern software development, enabling everything from simple code changes to complex collaboration workflows.
Created by Linus Torvalds, Git has become the standard for distributed version control across the development world. Whether you’re working with a local repository or managing a massive codebase on GitHub, understanding these commands is crucial.
This guide will take you from basic operations like git init and git commit to advanced techniques such as rebasing and resolving conflicts. You’ll learn:
- Essential commands for daily development
- Techniques for effective branching and merging
- Best practices for maintaining clean commit history
- Advanced workflow strategies using hooks and GitFlow
Stop copying commands you don’t understand. Let’s demystify Git commands and transform how you work with your repositories.
Git Commands To Use
Setup and Configuration
git config
: Sets configuration options for Git installation.git init
: Creates a new Git repository in the current directory.git clone
: Creates a copy of an existing repository.git help
: Displays help information about Git commands.git bugreport
: Collects information for user to file a bug report.
Basic Snapshotting
git add
: Adds file contents to the staging area.git status
: Shows the working tree status.git diff
: Shows changes between commits, commit and working tree, etc.git commit
: Records changes to the repository.git notes
: Adds or inspects object notes.git restore
: Restores working tree files (new alternative to checkout).git reset
: Resets current HEAD to the specified state.git rm
: Removes files from the working tree and from the index.git mv
: Moves or renames a file, directory, or symlink.
Branching and Merging
git branch
: Lists, creates, or deletes branches.git checkout
: Switches branches or restores working tree files.git switch
: Switches branches (newer alternative to checkout).git merge
: Joins two or more development histories together.git mergetool
: Runs merge conflict resolution tools.git log
: Shows commit logs.git stash
: Stashes changes in a dirty working directory.git tag
: Creates, lists, deletes, or verifies a tag object.git worktree
: Manages multiple working trees attached to the same repository.
Sharing and Updating
git fetch
: Downloads objects and refs from another repository.git pull
: Fetches from and integrates with another repository or branch.git push
: Updates remote refs along with associated objects.git remote
: Manages set of tracked repositories.git submodule
: Manages nested repositories within a parent repository.git svn
: Bidirectional operation between a Subversion repository and Git.git p4
: Import from and submit to Perforce repositories.
Inspection and Comparison
git show
: Shows various types of objects.git log
: Displays commit history.git diff
: Shows changes between commits, branches, etc.git difftool
: Shows changes using common diff tools.git range-diff
: Compares two commit ranges.git shortlog
: Summarizes git log output.git describe
: Shows the most recent tag that is reachable from a commit.git blame
: Shows what revision and author last modified each line of a file.git annotate
: Similar to blame, annotates each line in a file with commit information.git grep
: Prints lines matching a pattern.git show-branch
: Shows branches and their commits.git name-rev
: Finds symbolic names for given revisions.git rev-parse
: Picks out and massages parameters for other Git commands.git count-objects
: Counts the number of unpacked objects and their disk consumption.git ls-files
: Shows information about files in the index and the working tree.git ls-tree
: Lists the contents of a tree object.git ls-remote
: Lists references in a remote repository.git rev-list
: Lists commit objects in reverse chronological order.git verify-commit
: Verifies the GPG signature of a commit.git verify-tag
: Verifies the GPG signature of a tag.git whatchanged
: Shows logs with difference each commit introduces.git show-ref
: Lists references in a local repository.git reflog
: Manages reflog information.git cherry
: Finds commits yet to be applied to upstream.
Patching
git apply
: Applies a patch to files and/or to the index.git cherry-pick
: Applies the changes introduced by existing commits.git rebase
: Reapplies commits on top of another base tip.git revert
: Creates new commits to reverse the effect of earlier ones.git am
: Applies a series of patches from a mailbox.git format-patch
: Prepares patches for email submission.git send-email
: Sends a collection of patches as emails.git request-pull
: Generates a summary of pending changes.
Debugging
git bisect
: Uses binary search to find the commit that introduced a bug.git blame
: Shows what revision and author last modified each line of a file.git grep
: Prints lines matching a pattern.git am
: Applies a series of patches from a mailbox.git reflog
: Manages reflog information.git trace
: Traces Git command execution.
Administration
git clean
: Removes untracked files from the working tree.git gc
: Cleans up unnecessary files and optimizes the local repository.git fsck
: Verifies the connectivity and validity of objects in the database.git reflog
: Manages reflog information.git filter-branch
: Rewrites Git revision history by rewriting branches.git instaweb
: Instantly browse your working repository in gitweb.git archive
: Creates an archive of files from a named tree.git bundle
: Moves objects and refs by archive.git prune
: Prunes all unreachable objects from the object database.git repack
: Packs unpacked objects in a repository.git pack-refs
: Packs heads and tags for efficient repository access.git update-server-info
: Updates auxiliary info file to help dumb servers.git maintenance
: Runs tasks to optimize Git repository data.git verify-pack
: Validates packed Git archive files.git fast-export
: Git data exporter.git fast-import
: Backend for fast Git data importers.git rerere
: Reuses recorded resolution of conflicted merges.git replace
: Creates, lists, and deletes refs to replace objects.git cvsexportcommit
: Exports a commit to a CVS checkout.git cvsimport
: Imports a CVS repository into Git.git cvsserver
: A CVS server emulator for Git.git check-attr
: Displays gitattributes information.git check-ignore
: Checks if a path is ignored by .gitignore.git check-mailmap
: Shows canonical names and email addresses of contacts.git check-ref-format
: Ensures that a reference name is well formed.git column
: Display data in columns.git credential
: Retrieve and store user credentials.git credential-cache
: Helper to temporarily store passwords in memory.git credential-store
: Helper to store credentials on disk.git daemon
: A really simple server for Git repositories.git hash-object
: Computes object ID and optionally creates a blob from a file.git http-backend
: Server side implementation of Git over HTTP.git http-fetch
: Downloads a remote Git repository via HTTP.git http-push
: Pushes objects over HTTP/DAV to another repository.git imap-send
: Sends a collection of patches from stdin to an IMAP folder.git interpret-trailers
: Adds or parse commit message trailers.git merge-base
: Finds best common ancestor(s) between two commits.git merge-file
: Runs a three-way file merge.git merge-index
: Runs a merge for files needing merging.git merge-one-file
: The standard helper program to use with git-merge-index.git merge-tree
: Shows three-way merge without touching index.git mktag
: Creates a tag object with extra validation.git mktree
: Build a tree-object from ls-tree formatted text.git multi-pack-index
: Writes and verifies a multi-pack-index file.git pack-objects
: Creates a packed archive of objects.git pack-redundant
: Finds redundant pack files.git patch-id
: Computes unique ID for a patch.git read-tree
: Reads tree information into the index.git receive-pack
: Receives what is pushed into the repository.git send-pack
: Pushes objects packed to a remote.git show-index
: Shows packed archive index.git unpack-file
: Creates a temporary file with a blob’s contents.git unpack-objects
: Unpacks objects from a packed archive.git update-index
: Registers file contents in the working tree to the index.git update-ref
: Updates the object name stored in a ref safely.git write-tree
: Creates a tree object from the current index.
GUI Commands
git gui
: A portable graphical interface to Git.git citool
: Graphical alternative to git commit.git gitk
: The Git repository browser.
External Systems
git svn
: Used to interact with Subversion repositories.git p4
: Import from and submit to Perforce repositories.git archive
: Creates an archive of files from a named tree.git fast-import
: Backend for fast Git data importers.git fast-export
: Git data exporter.git cvsexportcommit
: Exports a commit to a CVS checkout.git cvsimport
: Imports a CVS repository into Git.git cvsserver
: A CVS server emulator for Git.
Email Commands
git imap-send
: Sends a collection of patches from stdin to an IMAP folder.git format-patch
: Prepares patches for email submission.git send-email
: Sends a collection of patches as emails.git request-pull
: Generates a summary of pending changes.git am
: Applies a series of patches from a mailbox.
Plumbing Commands (Low-level)
git cat-file
: Provides content or type and size information for repository objects.git check-ignore
: Checks if a path is ignored by .gitignore.git commit-tree
: Creates a new commit object.git count-objects
: Counts the number of unpacked objects and their disk consumption.git diff-index
: Compares content and mode of blobs between index and repository.git diff-tree
: Compares the content and mode of blobs found via two tree objects.git for-each-ref
: Output information on each ref.git hash-object
: Computes object ID and optionally creates a blob from a file.git ls-files
: Shows information about files in the index and the working tree.git ls-tree
: Lists the contents of a tree object.git merge-base
: Finds best common ancestor(s) between two commits.git read-tree
: Reads tree information into the index.git rev-list
: Lists commit objects in reverse chronological order.git rev-parse
: Picks out and massages parameters for other Git commands.git show-ref
: Lists references in a local repository.git symbolic-ref
: Reads, modifies and deletes symbolic refs.git update-index
: Registers file contents in the working tree to the index.git update-ref
: Updates the object name stored in a ref safely.git verify-pack
: Validates packed Git archive files.git write-tree
: Creates a tree object from the current index.
Server Admin Commands
git daemon
: A really simple server for Git repositories.git update-server-info
: Updates auxiliary info file to help dumb servers.git http-backend
: Server side implementation of Git over HTTP.git instaweb
: Instantly browse your working repository in gitweb.git shell
: Restricted login shell for Git-only SSH access.git upload-archive
: Sends archive back to git-archive client.git upload-pack
: Sends objects packed to git-fetch-pack client.git receive-pack
: Receives what is pushed into the repository.
Extension Commands
git lfs
: Git Large File Storage (LFS) extension commands.git flow
: Git-flow workflow extension commands.git hooks
: Scripts that run automatically every time a particular event occurs.git subtree
: Merges and splits subtrees from the main project.
Sync & Backup Commands
git bundle
: Moves objects and refs by archive.git fetch-pack
: Receives missing objects from another repository.git push
: Updates remote refs along with associated objects.git fetch
: Downloads objects and refs from another repository.git pull
: Fetches from and integrates with another repository or branch.
Misc Helper Commands
git command
: Runs an arbitrary git command.git var
: Shows a Git logical variable.git version
: Shows Git version info.git web--browse
: Opens git web pages.git quiltimport
: Applies a quilt patchset onto the current branch.git difftool--helper
: Used by git difftool.git sh-i18n
: Prepares Git shell scripts for internationalization.git sh-setup
: Common Git shell script setup code.
Under-the-Hood Implementation Commands
git index-pack
: Builds pack index file for an existing packed archive.git mailinfo
: Extracts patch and authorship from a single email message.git mailsplit
: Simple UNIX mbox splitter program.git mktag
: Creates a tag object with extra validation.git mktree
: Build a tree-object from ls-tree formatted text.git multi-pack-index
: Writes and verifies a multi-pack-index file.git pack-objects
: Creates a packed archive of objects.git prune-packed
: Removes extra objects that are already in pack files.git show-index
: Shows packed archive index.git stripspace
: Removes unnecessary whitespace.git unpack-file
: Creates a temporary file with a blob’s contents.git unpack-objects
: Unpacks objects from a packed archive.
FAQ on Git Commands
What is Git and why should I use it?
Git is a distributed version control system created by Linus Torvalds. It tracks code changes over time, allowing you to revert to previous versions, branch off to try new ideas, and collaborate with others. Unlike older systems, Git stores complete snapshots rather than just differences, making it faster and more reliable for managing your codebase.
How do I start a new Git repository?
Use git init to create a new local repository in your current directory. This sets up the necessary structure for Git to track your files. For existing projects on GitHub or GitLab, use git clone followed by the repository URL to download and set up a local copy with tracking already configured.
What’s the difference between git pull and git fetch?
Git fetch downloads changes from a remote repository but doesn’t merge them into your working files. It’s safer when you want to review changes before integrating. Git pull combines fetch and merge into one command, immediately updating your local repository with remote changes. Choose based on your preferred workflow.
How do I undo the last commit?
Use git reset HEAD~1 to undo the last commit while keeping changes in your staging area. For a complete reversal, use git reset –hard HEAD~1, but be careful—this permanently discards those changes. Alternatively, git revert creates a new commit that undoes previous changes while preserving commit history.
What’s the proper way to handle merge conflicts?
When conflicts occur during merging or rebasing, Git marks the problematic areas in your files. Edit these markers manually to resolve differences, or use a Git GUI client like GitHub Desktop. After fixing conflicts, run git add on the resolved files, then complete the merge with git commit or continue rebasing.
How do I create and switch between branches?
Create a new branch with git branch [name] and switch to it with git checkout [name]. Alternatively, use the shortcut git checkout -b [name] to create and switch in one command. Branches are lightweight pointers that allow parallel development without affecting your main codebase.
What are Git hooks and how do I use them?
Git hooks are scripts that run automatically before or after Git events like commits or pushes. They’re stored in the .git/hooks directory. Common uses include enforcing commit message conventions, running tests before pushing, or triggering continuous integration. They’re powerful tools for maintaining quality in team workflows.
How do I revert to a specific previous commit?
First, find the commit using git log. Then use git checkout [commit hash] to temporarily view that version, or git reset –hard [commit hash] to permanently revert. For a safer approach, use git revert [commit hash] to create a new commit that undoes the specified changes.
What’s the difference between merge and rebase?
Merging combines branches with a new commit, preserving the full commit history. It’s simpler but can create cluttered histories. Rebasing replays your changes on top of another branch, creating a linear history. It’s cleaner but rewrites history, which can be problematic for pushed changes shared with others.
How do I ignore files in Git?
Create a .gitignore file in your repository root and list patterns of files to ignore. Common examples include build artifacts, dependencies, and environment-specific files. Git will skip these during add operations. This keeps your repository clean and prevents sensitive information from being tracked in source code.
Conclusion
Git commands are more than just terminal instructions—they’re powerful tools that transform how developers build software. From simple operations like git status and git add to complex operations with GitFlow or branch protection rules, mastering these commands gives you control over your development process.
Remember these key takeaways:
- Command line fluency makes you faster than any Git GUI client
- Understanding commit message conventions improves team communication
- Regular practice with stashing, cherry-pick, and reflog saves time during complex situations
- Learning merge conflict resolution techniques prevents development bottlenecks
The journey from beginner to Git expert isn’t about memorizing every command—it’s about understanding the underlying version control concepts. Start with the basics, gradually explore advanced workflows, and soon you’ll navigate your repositories with confidence.
Ready to level up? Grab a Git cheat sheet, open your terminal, and start practicing. Your future self will thank you.
- What Is Gitignore? Understand It in 5 Minutes - May 22, 2025
- Why Embedded Systems Are Crucial for Modern Product Success - May 22, 2025
- What Is MVC? Understanding the Classic Software Pattern - May 21, 2025