Loading...
Loading...
Free online Git command reference. Browse and copy common Git commands grouped by category.
Configure user name
git config --global user.name "Your Name"Configure user email
git config --global user.email "you@example.com"Check configuration
git config --listInitialize new repo
git initClone repository
git clone <url>Clone with branch
git clone -b <branch> <url>Check status
git statusStage all changes
git add .Stage specific file
git add <file>Commit changes
git commit -m "message"Commit with all staged
git commit -am "message"View commit log
git log --oneline --graphList branches
git branchCreate branch
git branch <name>Switch branch
git checkout <name>Create and switch
git checkout -b <name>Merge branch
git merge <branch>Delete branch
git branch -d <name>Add remote
git remote add origin <url>Push to remote
git push -u origin mainPull from remote
git pullFetch all remotes
git fetch --allUnstage file
git restore --staged <file>Discard changes
git restore <file>Amend last commit
git commit --amendReset to commit
git reset --hard <commit>Revert commit
git revert <commit>Show unstaged diff
git diffShow staged diff
git diff --stagedDiff two commits
git diff <commit1> <commit2>Stash changes
git stashList stashes
git stash listApply stash
git stash popCreate tag
git tag <name>Push tags
git push --tagsGit is a distributed version control system created by Linus Torvalds in 2005 for Linux kernel development. Unlike centralized systems (SVN, CVS), every Git clone is a full backup of the entire repository with complete history. This makes Git incredibly resilient, fast for most operations, and ideal for both solo developers and large distributed teams.
The core Git workflow centers on three areas: the working directory (your current files), the staging area (index — where you prepare changes for commit), and the repository (the .git directory with complete history). Changes flow from working directory → staging area → repository through git add and git commit commands.
Branching is Git's killer feature. Creating a branch costs almost nothing in Git — just a 41-byte file. This enables lightweight feature branching, where developers work on isolated branches and merge back via pull requests. Git's merge algorithm (three-way merge with recursive strategy) handles complex merge scenarios that would confuse older systems.
Distributed workflows are Git's other major innovation. Developers can commit locally, create branches, and experiment without affecting anyone else. The 'push' and 'pull' operations synchronize with remote repositories (GitHub, GitLab). This enables workflows like GitFlow, GitHub Flow, trunk-based development, and fork-and-pull collaboration models.
Git's flexibility comes with a learning curve. Common commands cover 90% of daily needs: git clone, add, commit, push, pull, branch, checkout, merge, log, status, and diff. More advanced features like rebase, bisect, stash, submodules, and reflog handle complex scenarios. Mastering these basic and intermediate commands is sufficient for most development work.
Git hooks are scripts that run automatically at key points in the Git workflow — before a commit (pre-commit), after a commit (post-commit), before pushing (pre-push), and others. Hooks can enforce code quality by running linters and formatters, prevent committing secrets or large files, or trigger deployment pipelines. While hooks live in the .git/hooks directory and are not tracked by version control, teams often share them through tools like Husky or Lefthook that manage hook installation from a configuration file.
Git is the version control system — the software that tracks changes. GitHub is a hosting platform for Git repositories that adds collaboration features: pull requests, issues, code review, CI/CD, and project management. You can use Git without GitHub, but GitHub adds value on top of Git.
A merge conflict occurs when two branches modify the same line of a file differently. Git cannot automatically decide which version to keep. To resolve, edit the conflicted file (marked with <<<<<<<, =======, >>>>>>>), choose the correct version, remove the markers, stage the file, and complete the merge.
Both integrate changes. Merge creates a merge commit preserving the full history of parallel development — good for public/shared branches. Rebase rewrites history by applying commits on top of a new base — creating a linear history. Use merge for shared branches (no history rewrite), rebase for cleaning up local commits before pushing.
Git hooks are scripts that run automatically at key workflow points — pre-commit, pre-push, post-commit, and more. They can run linters and formatters before commits, prevent committing secrets or large files, or trigger deployments. Hooks live in .git/hooks (not version-controlled), but tools like Husky or Lefthook help teams share and manage hooks via configuration files.
If the commit is only local (not pushed), use git reset --soft HEAD~1 to undo the commit while keeping your changes staged, or git reset --hard HEAD~1 to discard everything. If already pushed, use git revert <commit-hash> to create a new commit that reverses the changes — never force-push to undo shared history.