Cheatography
https://cheatography.com
This is a cheat sheet for basic git commads
This is a draft cheat sheet. It is a work in progress and is not finished yet.
Configuration
git config --global user.name "Your Name" |
Set your username globally. |
git config --global user.email "your.email@example.com" |
Set your email globally |
Starting a Repository
git init |
Initialize a new Git repository in the current directory. |
Basic Workflow
git status |
Check the status of your working directory and staging area |
git add <file> |
Add a file to the staging area. |
git commit -m "Commit message" |
Commit changes with a descriptive message |
git commit -am "Commit message" |
Add and commit changes in one step (only for modified files, not new files). |
git add submodule <link> <Directory> |
Adding a submodule |
Branching
git branch |
List all local branches |
git branch <branch_name> |
Create a new branch |
git checkout <branch_name> |
Switch to a different branch |
git checkout -b <branch_name> |
Create and switch to a new branch in one step |
git merge <branch_name> |
Merge changes from <branch_name> into the current branch |
git branch -d <branch_name> |
Deleting a branch |
Remote Repositories
git remote add <name> <url> |
Add a new remote repository |
git remote -v |
List all remote repositories |
git pull <remote> <branch> |
Fetch changes from the remote repository and merge them into the current branch |
git push <remote> <branch> |
Push changes from the local repository to the remote |
Inspecting Changes
git log |
View commit history |
git diff |
Show changes between commits, commit and working tree, etc |
git show <commit_hash> |
Show details of a specific commit |
Undoing Changes
git reset HEAD <file> |
Unstage a file from the staging area. |
git checkout -- <file> |
Discard changes in the working directory for a specific file |
git reset --hard <commit_hash> |
Reset the repository to a specific commit (WARNING: this is a destructive operation). |
|
|
Miscellaneous
git clone <repository_url> |
Clone a remote repository to your local machine |
git pull |
Fetch changes from the remote repository and merge them into the current branch |
git push |
Push changes from the local repository to the remote repository |
git submodule update –remote |
Updating submodule |
Optional tags
-a, --all |
Includes all changes (both tracked and untracked files) when executing the command |
-m, --message <message> |
Specifies a commit message inline with the command |
-b, --branch <branch_name> |
Specifies the branch name when creating a new branch or switching branches |
-f, --force |
Forces the command to execute, even if it would result in data loss or conflicts |
-t, --tags |
Pushes tags along with the commits when pushing changes to a remote repository |
-u, --set-upstream <upstream> |
Sets the upstream branch for the current branch |
-v, --verbose |
Provides more detailed output, often helpful for debugging or understanding what the command is doing |
-p, --patch |
Allows for interactive patching of changes (e.g., for selecting specific changes to include in a commit) |
-d, --delete |
Deletes a branch or tag |
-i, --interactive |
Runs the command in interactive mode, allowing for user input and interaction |
|