Master Git Commands
Learn Git from beginner to advanced with our comprehensive command reference, interactive examples, and step-by-step tutorials.
Git Cheat Sheet
Download our comprehensive Git cheat sheet
Interactive Tutorial
Try our hands-on Git tutorial
GitHub Documentation
Official Git documentation
Practice Repository
Clone and practice with our sample repo
git config --global user.name 'Your Name'Set the name that will be attached to your commits and appears in the commit history.
git config --global user.email 'youremail@example.com'Set the email address that will be attached to your commits for identification.
git config --global init.defaultBranch mainSet the default branch name to 'main' for all new repositories you create.
git config --global core.editor 'code --wait'Set VS Code as your default Git editor for commit messages and merge conflicts.
git initInitialize a new, empty Git repository in the current directory. Creates a .git folder.
git clone https://github.com/user/repo.gitCreate a local copy of a remote repository. Downloads all files and commit history.
git statusShow the working tree status including untracked, modified, and staged files.
git add <file>Add file contents to the staging area. Use 'git add .' to add all changes.
git commit -m 'Your commit message'Record changes to the repository with a descriptive message. Be specific and clear.
git pushUpdate the remote repository with your committed changes from the current branch.
git pullFetch changes from the remote repository and merge them into your current branch.
git fetchDownload objects and refs from another repository without merging changes.
git branchList all local branches. Add '-r' for remote or '-a' for all branches.
git branch <branch-name>Create a new branch with the specified name without switching to it.
git checkout <branch-name>Switch to an existing branch. Use '-b' to create and switch in one step.
git switch <branch-name>Modern way to switch branches. More intuitive than checkout for branch switching.
git merge <branch-name>Join the specified branch's history into the current branch.
git rebase <branch-name>Re-apply commits from your current branch onto the tip of another branch.
git commit --amendModify the most recent commit. Useful for fixing typos or adding forgotten changes.
git reset HEAD <file>Unstage a file, but preserve its content in the working directory.
git reset --soft HEAD~1Undo the last commit but keep the changes staged for recommitting.
git reset --hard HEAD~1DANGEROUS: Discard the last commit and all changes. Use with extreme caution!
git revert <commit-hash>Create a new commit that undoes the changes of a previous commit safely.
git logShow the commit history. Use '--oneline' for a compact view.
git log --graph --oneline --decorateDisplay the commit history as a visual graph with branch information.
git diffShow changes between commits, working tree, etc. Use '--staged' for staged changes.
git show <commit-hash>Show metadata and content changes of the specified commit.
git blame <file>Show what revision and author last modified each line of a file.
git remote -vList all remote repositories with their URLs.
git remote add origin <url>Add a new remote repository with the name 'origin'.
git push -u origin mainPush a local branch to a remote repository and set it as the upstream branch.
git remote remove <name>Remove a remote repository from your local Git configuration.
Ready to Generate Your README?
Now that you've learned Git, create a professional README for your repository!
Generate README Now