GIT Cheatsheet: Most useful GIT commands
Git commands with params - little ref
Page content
Here’s a little cheatsheet: Git commands with params
This streetscape image is generated by AI model Flux 1 dev.
Basic Commands
git init: Initialize a new Git repositorygit clone <url>: Create a local copy of a remote repositorygit add <file>: Stage changes for commitgit commit -m "<message>": Save changes to the local repository with a messagegit status: Check the status of your working directorygit log: View commit history
Branching and Merging
git branch: List all local branchesgit branch <branch-name>: Create a new branchgit checkout <branch-name>: Switch to a different branchgit checkout -b <branch-name>: Create and switch to a new branchgit merge <branch>: Merge specified branch into the current branch
Remote Repositories
git remote add <name> <url>: Add a remote repositorygit push <remote> <branch>: Upload local commits to a remote repositorygit pull: Fetch and merge changes from the remote repositorygit fetch: Download changes from the remote repository
Undoing Changes
git reset <file>: Unstage changes while keeping them in the working directorygit reset --hard <commit>: Discard all changes and move to a specific commitgit revert <commit>: Create a new commit that undoes the changes from a specific commit
Advanced Commands
git stash: Temporarily store modified filesgit stash pop: Apply and remove the most recent stashgit rebase <branch>: Reapply commits on top of another basegit cherry-pick <commit>: Apply a specific commit to the current branchgit tag <tag-name>: Create a lightweight tag at the current commit
Configuration
git config --global user.name "<Your Name>": Set the name for your commitsgit config --global user.email "<you@example.com>": Set the email for your commits
Replace placeholders like <file>, <url>, <branch-name>, etc., with actual values when using these commands.
Useful links
- https://en.wikipedia.org/wiki/Git
- https://www.atlassian.com/git/tutorials/atlassian-git-cheatsheet
- https://about.gitlab.com/images/press/git-cheat-sheet.pdf
- https://education.github.com/git-cheat-sheet-education.pdf