Here’s a ready-to-use Git Command Cheat Sheet for your blog:
Git Command Cheat Sheet :
Git is an essential tool for developers to manage code, track changes, and collaborate on projects. Here's a comprehensive cheat sheet to help you master Git commands!
Basic Git Commands
-------------------------------------
git init: Initialize a new Git repository in your project folder.
git clone <repository_url>: Clone an existing repository to your local machine.
git status: Check the status of your working directory and staging area.
git add <file>: Stage specific changes for commit.
git add .: Stage all changes in the current directory.
git commit -m "message": Save staged changes with a descriptive commit message.
Branching and Merging
git branch: View all branches in your repository.
git branch <branch_name>: Create a new branch.
git checkout <branch_name>: Switch to an existing branch.
git checkout -b <branch_name>: Create and switch to a new branch in one step.
git merge <branch_name>: Merge the specified branch into the current branch.
git branch -d <branch_name>: Delete a branch after merging.
Working with Remote Repositories
git remote add <name> <url>: Add a remote repository.
git fetch <remote>: Retrieve updates from the remote repository without merging.
git pull: Fetch updates from the remote repository and merge them into your current branch.
git push <remote> <branch>: Push your commits to the specified branch on a remote repository.
Viewing and Tracking Changes
git log: View the commit history.
git log --oneline: View a condensed version of the commit history.
git diff: See changes in unstaged files.
git diff --staged: View changes in files staged for commit.
Undoing Changes
git restore <file>: Discard changes in the working directory.
git restore --staged <file>: Unstage a file without discarding changes.
git reset <commit>: Reset the current branch to a specific commit (keeps working directory changes).
git reset --hard <commit>: Reset the branch and discard all changes.
Stashing Changes
git stash: Save your changes temporarily without committing.
git stash list: View all stashes.
git stash apply: Apply stashed changes back to your working directory.
git stash drop: Delete a stash after applying it.
Tags
git tag <tag_name>: Create a lightweight tag for a specific commit.
git tag: List all tags in the repository.
git push <remote> <tag_name>: Push a tag to the remote repository.
Miscellaneous Commands
git config --global user.name "Your Name": Set your global Git username.
git config --global user.email "your.email@example.com": Set your global Git email address.
git clean -f: Forcefully remove untracked files from the working directory.
git blame <file>: Show changes and authors for each line in a file.
Save this cheat sheet for quick reference during your projects. Git is a powerful tool, and mastering it will enhance your productivity as a developer!
Thanks for watching my blog😊
Yours VK
No comments:
Post a Comment