0% found this document useful (0 votes)
21 views

GIT CheatSheet

Uploaded by

lekoma3772
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

GIT CheatSheet

Uploaded by

lekoma3772
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Git Cheat Sheet – 50 Git

Commands You Should


Know
@Shreya_Chauhan
Introduction to Git:
• Git is a powerful and widely-used version control system that revolutionizes the
way developers collaborate on projects, track changes, and manage code.
• Whether you're working on a small personal project or contributing to a large
team effort, Git helps you maintain a clear history of your codebase, facilitates
efficient collaboration, and empowers you to work confidently.
• At its core, Git is like a time machine for your code. It allows you to capture
snapshots of your work at different points in time, making it easy to track changes,
compare versions, and collaborate with others seamlessly.
• With Git, you can work on new features, fix bugs, experiment with ideas, and
safely roll back to previous states if needed.
Getting Started:
1.git init: Initialize a new Git repository.
2.git clone [repository URL]: Clone an existing repository to your local machine.
3.git config --global user.name "Your Name": Set your global Git username.
4.git config --global user.email "[email protected]": Set your global Git
email.
5.git remote add [remote-name] [repository URL]: Link a remote repository to your
local repository.
Basic Workflow:
6.git add [file(s)]: Stage changes for commit.
7.git commit -m "Commit message": Save staged changes with a message.
8.git status: Check status of your working directory.
9.git diff: Display differences between working directory and last commit.
10.git log: View commit history.
11.git show [commit]: Display detailed information about a specific commit.
Branching and Merging:
12.git branch: List, create, or delete branches.
13.git checkout [branch-name]: Switch to a different branch.
14.git merge [branch-name]: Combine changes from one branch into another.
15.git pull [remote] [branch]: Fetch and integrate changes from remote repository.
16.git push [remote] [branch]: Upload local commits to remote repository.
17.git stash: Temporarily save changes without committing.
18.git stash apply: Apply changes from a stash.
19.git stash pop: Apply and remove changes from a stash
Remote Collaboration:
20.git remote -v: List remote repositories.
21.git fetch [remote]: Fetch changes from remote without merging.
22.git pull [remote] [branch]: Fetch and merge changes from remote repository.
23.git push [remote] [branch]: Upload local commits to remote repository.
24.git remote show [remote]: Display information about a remote repository.
25.git clone [repository URL]: Clone an existing repository to your local machine.
Tagging and Versioning:
26.git tag: List, create, or delete tags.
27.git tag [tag-name]: Create a lightweight tag at the current commit.
28.git tag -a [tag-name] -m "Tag message": Create an annotated tag with a
message.
Advanced Commands:
29.git rebase [branch]: Reapply commits on top of another branch.
30.git cherry-pick [commit]: Apply a specific commit to the current branch.
31.git blame [file]: Show who changed which lines in a file.
32.git log --graph --oneline --all: Display a compact graph of commit history.
33.git reflog: View a log of all Git commands that have been executed.
Configuration and Customization:
34.git config --local: Set configuration options for the current repository.
35.git config --global: Set configuration options globally.
36.git config --system: Set configuration options system-wide.
Git Aliases:
git config --global alias.[alias-name] "[git-command]": Create shortcuts (aliases) for
Git commands.
Ignoring Files:
.gitignore: Create a file to specify files and directories to ignore in version control.
Git Hooks:
.git/hooks: Explore and customize Git hooks for automation.
Submodules:
git submodule add [repository URL]: Add a submodule to your repository.
git submodule init: Initialize submodules after cloning.
git submodule update: Update submodules to the latest version.
Rewriting History:
git commit --amend: Edit the last commit message or content.
git rebase -i [commit]: Interactive rebase to squash, edit, or reorder commits.
Git Reset:
git reset [commit]: Unstage changes from the staging area.
git reset --hard [commit]: Discard changes and reset to a specific commit.
Git Bisect:
git bisect start: Begin a binary search to find a faulty commit.
Git Archive:
git archive --format=zip --output=[output-file] [commit]: Create a ZIP archive of a
specific commit.
Git Subtree:
git subtree: Manage and work with subtrees within your repository.
Git LFS (Large File Storage):
git lfs: Use Git LFS to manage large binary files.
This cheat sheet covers a wide range of Git commands
that can help you effectively manage your version
control tasks and collaborate with others in your
development projects.

Remember that practice and hands-on experience are


key to becoming proficient with Git.
THANK YOU

You might also like