Git Command Summary
Getting Started
Initialize a Repository:
Creates a new Git repository in your project directory.
Clone a Repository:
Downloads a repository from a remote source (e.g., GitHub).
Set Up Git Configuration:
Set your username:
Set your email address:
Check your configuration:
Displays all configured settings.
Set your preferred editor (e.g., VS Code):
Note: The
--global
flag applies settings to all repositories; omit it for repository-specific settings.
Basic Commands
Check the Status:
Shows the current status of your files (e.g., staged, modified, untracked).
Add Files to Staging:
Adds files to the staging area (
.
stages all files).Commit Changes:
Saves the staged changes with a message describing them.
Working with Changes
View Changes:
Displays changes between the working directory and the staging area.
View Commit History:
Shows the commit history with details.
Undo Changes:
- Unstage a file:
- Discard changes in a file:
- Unstage a file:
Revert a Commit:
Creates a new commit that undoes the changes made by a specific commit (safe for collaborative workflows).
View Reference Logs:
Shows a log of all the actions (e.g., commits, checkouts) performed in your repository. Useful for recovering lost commits.
Branching and Merging
Create a New Branch:
Creates a new branch.
Switch to a Branch:
Moves to the specified branch.
Merge Branches:
Merges another branch into the current branch.
Delete a Branch:
Working with Remotes
View Remote Repositories:
Lists remote repositories.
Push Changes to Remote:
Sends changes to a remote repository.
Pull Changes from Remote:
Fetches and merges changes from a remote repository.
Fetch Remote Changes:
Retrieves changes from a remote repository but does not merge them.
Advanced Essentials
Stash Changes:
Temporarily saves uncommitted changes.
Apply Stashed Changes:
Tagging a Commit:
Adds a tag to a specific commit.
Recover Lost Actions:
Tracks all changes (even detached HEAD or commits accidentally dropped) to recover lost work.
Bonus: Setting Up Aliases
- Create Shortcuts for Commands:
Use these shortcuts to speed up common commands (e.g.,
git st
instead ofgit status
).
Comments
Post a Comment