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

Git Commands Guide

Uploaded by

nm.nielit
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Git Commands Guide

Uploaded by

nm.nielit
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Brij Kishore Pandey

@brijpandeyji

Git
Commands
Guide Swipe
Git Commands
Cheat Sheet
Unlock the power of Git with this
essential guide to daily commands.

Swipe
Setting Up and
Configuring Git

git init: Initialize a new Git repository.


git clone [URL]: Download a repository onto
your local machine.
git config --global user.name "[name]":
Set your username for all repositories.
git config --global user.email "[email
address]": Set your email for all
repositories.
git config --list: List all settings configured
in git config.

Swipe
Managing Files
and Staging

git status: Show the status of files in the


working directory and staging area.
git add [file]: Add a file to the staging
area.
git rm [file]: Remove a file from the
working directory and the staging area.
git mv [old-file] [new-file]: Move or
rename a file or a directory.
git diff: Show changes between files,
commit, and staging area.

Swipe
Branching and
Merging

git branch: List all branches in your repo.


git branch [name]: Create a new
branch.
git checkout [branch]: Switch to
another branch and check it out into
your working directory.
git merge [branch]: Merge another
branch into your active branch.
git branch -d [branch]: Delete a branch.

Swipe
Committing
Changes

git commit -m "[message]": Commit your


staged content as a new commit snapshot.
git commit --amend: Modify the most
recent commit.
git revert [commit]: Revert some existing
commits.
git reset [file]: Unstage a file while retaining
the changes in working directory.
git clean -n: Show which files would be
removed from working directory.

Swipe
Remote Repositories
and Pushing Changes

git remote add [name] [url]: Add a new


remote repository.
git fetch [remote]: Fetch changes from
the remote repository.
git pull [remote] [branch]: Fetch and
merge changes on the remote server to
your working directory.
git push [remote] [branch]: Push your
branch to the remote repository.
git remote show [remote]: Give detailed
information about a particular remote.

Swipe
Advanced Branching
and Merging

git checkout -b [branch]: Create and check


out a new branch.
git merge --no-ff [branch]: Merge without a
fast-forward.
git stash push: Save your modifications
temporarily without committing.
git stash pop: Apply stashed changes back
to your working directory.
git cherry-pick [commit]: Apply the
changes introduced by some existing
commits.

Swipe
Tagging and Logging

git tag [tag]: Create a tag for marking a


significant change.
git log: Show recent commits on the
current branch.
git log --follow [file]: Show the commits
that changed a file.
git show [commit]: Show various types
of objects.
git tag -a [tag] -m [msg]: Create an
annotated tag.

Swipe
Undoing Changes
and Cleaning Up

git reset --hard [commit]: Reset your HEAD


and working directory to another commit.
git revert [commit]: Generate a new
commit that undoes all of the changes
introduced in [commit].
git clean -f: Remove untracked files from
the working directory.
git reset --soft [commit]: Soft reset on a
commit.
git reset --mixed [commit]: Resets the
index but not the working tree.

Swipe
Advanced Git Tools

git bisect start: Start binary search to find


the commit that introduced a bug.
git bisect good [commit]: Mark commit as
good.
git bisect bad [commit]: Mark commit as
bad.
git grep [pattern]: Search for a pattern in
the tracked files in your repository.
git blame [file]: Show what revision and
author last modified each line of a file.

Swipe
Collaboration and
Workflow

git pull --rebase [remote]: Reapply


changes from a remote branch.
git push --force [remote] [branch]:
Force push to a remote repository.
git fetch --all: Fetch all remotes.
git push --tags: Push all tags to remote
repository.
git pull --all: Pull changes from all
branches and merge them.

Swipe
Git Mastery
Leverage these Git commands to
enhance your development
workflows, improve collaboration,
and streamline your projects.

Swipe
Brij Kishore Pandey
@brijpandeyji
Follow for More

You might also like