0% found this document useful (0 votes)
152 views4 pages

Git Cheat Sheet: by Thesyntacticsugar

This document provides a cheat sheet for using common Git commands. It introduces how to install Git, configure user settings, perform basic operations like initializing a repository, adding files, committing changes, and viewing the commit history and status of files. It also summarizes commands for branching and merging, working with remote repositories, logging commits in different ways, diffing files and commits, and resetting or rewriting the commit history. The full cheat sheet contains over 40 Git commands organized into sections covering the basic workflow and more advanced topics.

Uploaded by

Rohan Gupta
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)
152 views4 pages

Git Cheat Sheet: by Thesyntacticsugar

This document provides a cheat sheet for using common Git commands. It introduces how to install Git, configure user settings, perform basic operations like initializing a repository, adding files, committing changes, and viewing the commit history and status of files. It also summarizes commands for branching and merging, working with remote repositories, logging commits in different ways, diffing files and commits, and resetting or rewriting the commit history. The full cheat sheet contains over 40 Git commands organized into sections covering the basic workflow and more advanced topics.

Uploaded by

Rohan Gupta
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/ 4

Git Cheat Sheet

By thesyntacticsugar

INSTALLATIONS:
Git for All Platforms https://windows.github.com

GitHub for Windows https://mac.github.com

GitHub for Mac http://git-scm.com

For Linux and Solaris platforms, the latest release is


available on the official Git website.

GIT CONFIGURATION:
The command returns a list of information
git config -l about your git configuration including user
name and email

git config --global With the command you can configure your user
user.name "Rupam" name

git config --global This command lets you setup the user email
user.email "[mail]" address you'll use in your commits.

git config --global


credential.helper You can store login credentials in the cache so
you don't have to type them in each time
cache

Check out: https://www.instagram.com/thesyntacticsugar/


GIT BASIC:
To initialize git in a directory open the folder in
git init the terminal and run this command to initialize
the directory as a git repo.

git add Add a file to the staging area. Just replace


filename_here with the name of the file you
filename_here
want to add to the staging area.

Add all files in your project to the staging area,


git add . you can use a wildcard . and every file will be
added for you.

With the asterisk in the command below, you


git add fil* can add all files starting with 'fil' in the staging
area.

Commit the staged snapshot, but instead of


git commit -m
launching a text editor, use as the commit
"your message" message.

git commit -a -m Add files to staging area and commit using a


"your message" single line of command

This command shows the commit history for the


git log
current repository.

Show modified files in working directory, staged


git status
for your next commit.

Show unstaged changes between your index


git diff
and working directory.

UNDO CHANGES:
Create new commit that undoes all of the
git revert
changes made in , then apply it to the current
<commit> branch.

Unstage a file while retaining the changes in


git reset <file>
working directory

Check out: https://www.instagram.com/thesyntacticsugar/


BRANCH & MERGE
git branch List all of the branches in your repo.

git branch
Create and check out a new branch named
[branch-name]

git checkout Switch to another branch and check it out into


[branch_name] your working directory

git merge Merge the specified branch’s history into the


<branch> current one

git branch -d When you are done working with a branch and
branch_name have merged it, you can delete it

REMOTE REPOSITORIES
Create a new connection to a remote repo.
git remote add
After adding a remote, you can use as a
[alias] [url] shortcut for in other commands.

Fetch down all the branches from that Git


git fetch [alias]
remote

You can see all remote repositories for your


git remote -v
local repository

Fetch and merge any commits from the tracking


git pull <remote>
remote branch

Push the branch to , along with necessary


git push -u [alias] commits and objects. Creates named branch in
[branch] the remote repo if it doesn’t exist.

git merge Merge a remote branch into your current branch


[alias]/[branch] to bring it up to date

git remote remove


Used to unlink remote origin from local repo
origin

Check out: https://www.instagram.com/thesyntacticsugar/


ADVANCED LOG
Show commits that occur between <m1> and
git log <m1>..<m2>
<m2>

git log --follow show the commits that changed file, even
[file] across renames

Include which files were altered and the relative


git log --stat number of lines that were added or deleted
from each of them.

Only display commits that have the specified


git log -- <file>
file.

ADVANCED DIFF
Show difference between working directory and
git diff HEAD last commit.

git diff Show the diff of what is in branchA that is not in


branchB...branchA branchB

Show difference between staged changes and


git diff --cached
last commit

REWRITE HISTORY
Show difference between working directory and
git reset last commit.

git reset --hard Clear staging area, rewrite working tree from
[commit] specified commit

Interactively rebase current branch onto .


Launches editor to enter commands for how
git rebase -i
each commit will be transferred to the new
base.

git rebase [branch] Apply any commits of current branch ahead of


specified one

Check out: https://www.instagram.com/thesyntacticsugar/

You might also like