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

Git Commands Cheat Sheet by PhoenixNAP

This document provides a cheat sheet of common Git commands for setting up and configuring a Git repository, managing and viewing files and commits, branching and merging, undoing changes, and making changes. It includes commands for initializing a repository, cloning a remote repository, viewing the status and history, creating, checking out and deleting branches, committing changes, rebasing and reverting commits, staging and committing files, and pushing/pulling from remote repositories.

Uploaded by

sahuaditya2009
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)
301 views

Git Commands Cheat Sheet by PhoenixNAP

This document provides a cheat sheet of common Git commands for setting up and configuring a Git repository, managing and viewing files and commits, branching and merging, undoing changes, and making changes. It includes commands for initializing a repository, cloning a remote repository, viewing the status and history, creating, checking out and deleting branches, committing changes, rebasing and reverting commits, staging and committing files, and pushing/pulling from remote repositories.

Uploaded by

sahuaditya2009
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/ 1

Git Commands Cheat Sheet

Git Setup Git Configuring Managing Files

git init [directory] create a Git repository from an existing git config --global user. set an author name that will be git status show the state of the current
directory name "[your_name]" attached to all commits by the directory (along with staged,
current user unstaged, and untracked files)
git clone [repo / URL] clone / download a repository onto
local machine git config --global user. set an email address that will be git log list the complete commit history of
email " attached to all commits by the the current branch
git clone [URL] [folder] clone a repository from a remote [email_address]" current user
location into a specified folder [folder] git log --all list all commits from all branches
on your local machine git config --global set Git's automatic command line
color.ui auto coloring git log [branch1]..[branch2] show which commits are on the first
branch, but not on the second one
git config --global alias. create a shortcut (alias) for a Git
[alias_name] command git diff see the difference between the
[git_command] working directory and the index
Git Branches (which changes have not been
git config --system set a default text editor for all the commited yet)
core.editor users on the machine
git branch list all branches in the repository [text_editor] get diff --cached see the difference between the last
commit and the index
git branch -a list all remote branches git config --global --edit open Git's global configuration
file get diff HEAD see the difference between the last
git branch [branch] create a new branch under the commit and the working directory
specified name
git show [object] show the content and metadata of
git checkout [branch] switch to another branch (either an an object (blob, tree, tag, or commit)
existing one or by creating a new
one under the specified name] Rewriting History
git branch -d [branch] delete a local branch
git commit --amend replace the last commit with a
git branch -m rename the branch you are combination of the staged
[new_branch_name] currently working in changes and the last commit
combined
Remote Repositories
git merge [branch] merge the specified branch with the
current branch git rebase [base] rebase the current branch with git remote add [name] create a new connection to a
the specified base (it can be a [URL] remote repository and give it a
branch name, tag, reference to a name to serve as a shortcut to
HEAD, or a commit ID) the URL

git reflog list changes made to the HEAD of git fetch [remote_repo] fetch a branch from a remote
Undoing Changes the local repository [branch] repository

git pull [remote_repo] fetch the specified repository and


git revert [file/directory] undo all changes in the specified
merge it with the local copy
file/directory by creating a new
commit and applying it to the
git push [remote_repo] push a branch to a remote
current branch Making Changes [branch] repository with all its commits
and objects
git reset [file] unstage the specified file without
overwriting changes git add [file/directory] stage changes for the next commit

git reset [commit] undo all changes that happened git add . stage everything in the directory for
after the specified commit an initial commit

git clean -n see which files should be removed git commit -m " commit the previously staged
from the current directory [descriptive_message]" snapshot in the version history with
a descriptive message included in
git clean -f remove the unnecessary files in the the command
directory

You might also like