| Command |
Name |
Description |
git init |
Initialize a New Git Repository |
Creates a new empty Git repository in the current directory by generating a .git folder, allowing Git to start tracking changes. |
git init -b <branch-name> |
Initialize with a Specific Branch Name |
Creates a new Git repository and sets the initial branch name to the specified name (for example, main). |
git init <directory> |
Initialize a Repository in a Specific Directory |
Creates a new Git repository inside the specified directory. If the directory does not exist, create it first. |
| Command |
Name |
Description |
git config --global user.name "Your Name" |
Set Git Username |
Sets the name that Git records as the author of your commits. |
git config --global user.email "you@example.com" |
Set Git Email |
Sets the email address associated with your Git commits. |
git config --list |
List All Configuration |
Displays all Git configuration settings from system, global, and local levels. |
git config --global --list |
List Global Configuration |
Displays only the Git configuration settings stored in the global configuration file. |
git config --global --edit |
Edit Global Configuration |
Opens the global Git configuration file in the configured text editor for manual editing. |
git config user.name |
Show Git Username |
Displays the currently configured Git username. |
git config user.email |
Show Git Email |
Displays the currently configured Git email address. |
git config --global init.defaultBranch main |
Set Default Branch |
Sets main as the default branch name for newly initialized Git repositories. |
git config --global core.editor "code --wait" |
Set Default Editor |
Configures Visual Studio Code as the default editor used by Git for commit messages and configuration editing. |
| Command |
Name |
Description |
git switch -c <new-branch-name> origin/<remote-branch-name> |
Create a New Branch from a Remote Branch |
Creates a new local branch based on a remote branch and switches to it. |
git branch -d <branch-name> |
Delete a Local Branch |
Deletes a local branch if it has already been merged. |
git push origin --delete <branch-name> |
Delete a Remote Branch |
Deletes a branch from the remote repository. |
| Command |
Name |
Description |
git add <file> |
Add Specific File |
Stages a specific file for the next commit. |
git add . |
Add Current Directory |
Stages all new, modified, and deleted files in the current directory and its subdirectories. |
git add -A |
Add All Changes |
Stages all new, modified, and deleted files across the entire repository. |
git add -u |
Update Tracked Files |
Stages modifications and deletions to tracked files only. New files are not staged. |
git add -p |
Patch Mode |
Interactively stages selected portions of changes. |
git add -i |
Interactive Mode |
Opens an interactive menu to review and stage changes. |
git add -f <file> |
Force Add |
Stages a file even if it is ignored by .gitignore. |
| Command |
Name |
Description |
git push |
Push Current Branch |
Push commits to the tracked remote branch. |
git push origin main |
Push to Specific Branch |
Push commits to the main branch on the origin remote. |
git push -u origin <branch-name> |
Push New Branch |
Push a new branch and set it as the upstream branch. |
git push --force |
Force Push |
Overwrite the remote branch history. Use with caution. |
git push --force-with-lease |
Safe Force Push |
Force push only if the remote branch has not changed. |
git push --all origin |
Push All Branches |
Push all local branches to the remote repository. |
git push --tags |
Push All Tags |
Push all local tags to the remote repository. |
git push origin <tag-name> |
Push Specific Tag |
Push a specific tag to the remote repository. |
git push origin --delete <branch-name> |
Delete Remote Branch |
Delete a branch from the remote repository. |
git push --dry-run |
Dry Run |
Preview what would be pushed without making any changes. |
| Command |
Name |
Description |
git rebase -i --root |
Interactive Rebase from the Root Commit |
Opens every commit in an interactive editor where you can choose actions such as pick, reword, edit, squash, fixup, drop, exec, break, and label to rewrite the entire commit history. |
| Command |
Name |
Description |
git restore . |
Discard All Unstaged Changes |
Restores all tracked files in the working directory to their current staged state, discarding all unstaged changes. |
git restore --staged . |
Unstage All Changes |
Removes all changes from the staging area while keeping the changes in the working directory. |
git restore --staged --worktree . |
Discard All Staged and Unstaged Changes |
Restores all tracked files to HEAD, discarding both staged and unstaged changes. |
git clean -fdn |
Preview Untracked Files and Directories |
Shows which untracked files and directories would be deleted without actually deleting them.
|
git clean -fd |
Remove Untracked Files and Directories |
Deletes all untracked files and directories from the working directory. |
| Command |
Name |
Description |
git stash |
Stash Current Changes |
Saves all tracked, uncommitted changes and restores the working directory to the last committed state. |
git stash push -m "<message>" |
Stash with a Message |
Saves changes with a descriptive message for easier identification. |
git stash list |
List All Stashes |
Displays all saved stashes. |
git stash apply |
Apply Latest Stash |
Applies the latest stash without removing it from the stash list. |
git stash pop |
Pop Latest Stash |
Applies the latest stash and removes it from the stash list. |
git stash drop stash@{<index>} |
Drop a Stash |
Deletes a specific stash. |
git stash clear |
Clear All Stashes |
Deletes all saved stashes. |
git stash -u |
Stash Including Untracked Files |
Stashes both tracked and untracked files. |
This project is licensed under the MIT License.