What is a Git Commands Cheat Sheet?
A Git Commands Cheat Sheet is a quick reference guide that presents a list of useful command-line instructions to help you with basic usage.
- Set Up
- git init: Initialize a local Git repository
- git clone <url>: Clone a repository from GitHub into your local machine
- Local Changes
- git status: Check the status of your files (tracked, untracked, modified, etc.)
- git add .: Add all current changes to the next commit
- git add <file>: Add some specific changes in <file> to the next commit
- git commit -m "<message>": Commit all added changes with a message
- Branching & Merging
- git branch: List all local branches
- git branch <branch-name>: Create a new branch
- git checkout <branch-name>: Switch to a particular branch
- git merge <branch-name>: Merge <branch-name> into current branch
- Remote Repository (e.g. GitHub)
- git remote add origin <url>: Set a remote named 'origin' at <url>
- git pull origin <branch-name>: Fetch changes from the remote and merge into current branch
- git push origin <branch-name>: Push local changes to the remote branch
- git log: View commit history
- git diff: Shows differences between your working directory and the index
- git stash: Temporarily saves changes that are not ready to be committed
- git reset: Resets your index and working directory to the state of your last commit
These are just some basic commands, and Git has a rich set of commands to support various version control scenarios. It would be good to learn and understand these commands before diving into more complex ones.