Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Git is the backbone of modern version control. Whether youβre a solo dev or part of a massive team, these 20 commands cover about 95% of your daily interactions with a repository.
- Getting Started & Setup
- git init: Initializes a brand-new local Git repository in your current folder.
- git clone [url]: Downloads an existing repository from a remote source (like GitHub) to your machine.
- git config --global user.name "Name": Sets the name that will be attached to your commit transactions.
- The Staging Area & Basics
- git status: The "Where am I?" command. It shows which files are modified, staged, or untracked.
- git add [file]: Moves changes from the working directory to the Staging Area. Use git add . to stage everything.
- git commit -m "message": Records the staged snapshot permanently in the version history.
- git diff: Shows the exact line-by-line changes in files that are not yet staged.
- Branching & Switching
- git branch: Lists all local branches. Adding a name (e.g., git branch feature-x) creates a new branch.
- git checkout [branch]: Switches your working directory to the specified branch.
- git checkout -b [new-branch]: A shortcut that creates a new branch and switches to it immediately.
- git switch [branch]: A more modern, intuitive command specifically for changing branches.
- Merging & Syncing
- git merge [branch]: Integrates the history of the specified branch into your current active branch.
- git pull: Fetches updates from the remote server and immediately merges them into your local branch.
- git fetch: Downloads all history from the remote tracking branches but does not merge them into your local work.
- git push: Uploads your local branch commits to the remote repository.
- Inspection & Cleanup
- git log: Displays the commit history for the current branch.
- git show [commit]: Shows the metadata and content changes of a specific commit.
- git stash: Temporarily shelves uncommitted changes so you can work on something else without committing "work in progress."
- git stash pop: Brings your stashed changes back into your working directory.
- git remote -v: Lists the remote repositories (URLs) linked to your local project.
- Pro Tip: If you ever get stuck in a "Vim" screen after a merge or commit, type :q! and hit Enter to exit without saving, or :wq to save and exit. It's a rite of passage for every developer!
Advertisement