Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Git Cheat Sheet - Software, Cheat Sheet of Software Development

Git Basics, Rewriting Git History, Undoing Changes, Remote Repositories, git diff, git pull and more GIT commands

Typology: Cheat Sheet

2020/2021

Uploaded on 04/23/2021

ekani
ekani 🇺🇸

4.7

(26)

265 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
git clean -n Shows which files would be removed from working directory. Use
the -f flag in place of the -n flag to execute the clean.
Push the branch to <remote>, along with necessary commits and
objects. Creates named branch in the remote repo if it doesn’t exist.
git push
<remote> <branch>
git reset <file> Remove <file> from the staging area, but leave the working directory
unchanged. This unstages a file without overwriting any changes.
git pull <remote> Fetch the specified remote’s copy of current branch and immediately
merge it into the local copy.
git revert
<commit>
Create new commit that undoes all of the changes made in
<commit>, then apply it to the current branch.
git fetch
<remote> <branch>
Fetches a specific <branch>, from the repo. Leave off <branch> to
fetch all remote refs.
git remote add
<name> <url>
Create a new connection to a remote repo. After adding a remote,
you can use <name> as a shortcut for <url> in other commands.
Undoing Changes
git diff Show unstaged changes between your index and working directory. Remote Repositories
git commit -m
"<message>"
Commit the staged snapshot, but instead of launching a text editor,
use <message> as the commit message.
git status List which files are staged, unstaged, and untracked.
git log Display the entire commit history using the default format.
For customization see additional options.
git branch List all of the branches in your repo. Add a <branch> argument to
create a new branch with the name <branch>.
git checkout -b
<branch>
Create and check out a new branch named <branch>. Drop the -b
flag to checkout an existing branch.
git merge <branch> Merge <branch> into the current branch.
Git Branches
git add
<directory>
Stage all changes in <directory> for the next commit.
Replace <directory> with a <file> to change a specific file.
git clone <repo>
git config
user.name <name>
Define author name to be used for all commits in current repo. Devs
commonly use --global flag to set config options for current user.
git rebase <base>
git reflog Show a log of changes to the local repository’s HEAD. Add
--relative-date flag to show date info or --all to show all refs.
Clone repo located at <repo> onto local machine. Original repo can be
located on the local filesystem or on a remote machine via HTTP or SSH.
git init
<directory>
Create empty Git repo in specified directory. Run with no arguments
to initialize the current directory as a git repository.
git commit
--amend
Replace the last commit with the staged changes and last commit
combined. Use with nothing staged to edit the last commit’s message.
Rebase the current branch onto <base>. <base> can be a commit ID,
a branch name, a tag, or a relative reference to HEAD.
Git Basics Rewriting Git History
Git Cheat Sheet
Visit atlassian.com/git for more information, training, and tutorials
pf2

Partial preview of the text

Download Git Cheat Sheet - Software and more Cheat Sheet Software Development in PDF only on Docsity!

git clean -n Shows which files would be removed from working directory. Use

the -f flag in place of the -n flag to execute the clean.

Push the branch to , along with necessary commits and

objects. Creates named branch in the remote repo if it doesn’t exist.

git push

git reset Remove from the staging area, but leave the working directory

unchanged. This unstages a file without overwriting any changes.

git pull Fetch the specified remote’s copy of current branch and immediately

merge it into the local copy.

git revert

Create new commit that undoes all of the changes made in

, then apply it to the current branch.

git fetch

Fetches a specific , from the repo. Leave off to

fetch all remote refs.

git remote add

Create a new connection to a remote repo. After adding a remote,

Undoing Changes you can use as a shortcut for in other commands.

git diff Show unstaged changes between your index and working directory.

Remote Repositories

git commit -m ""

Commit the staged snapshot, but instead of launching a text editor,

use as the commit message.

git status List which files are staged, unstaged, and untracked.

git log Display the entire commit history using the default format.

For customization see additional options.

git branch List all of the branches in your repo. Add a argument to

create a new branch with the name .

git checkout -b

Create and check out a new branch named . Drop the -b

flag to checkout an existing branch.

git merge Merge into the current branch.

Git Branches

git add

Stage all changes in for the next commit.

Replace with a to change a specific file.

git clone git config user.name

Define author name to be used for all commits in current repo. Devs

commonly use --global flag to set config options for current user.

git rebase

git reflog Show a log of changes to the local repository’s HEAD. Add

--relative-date flag to show date info or --all to show all refs.

Clone repo located at onto local machine. Original repo can be

located on the local filesystem or on a remote machine via HTTP or SSH.

git init

Create empty Git repo in specified directory. Run with no arguments

to initialize the current directory as a git repository.

git commit --amend

Replace the last commit with the staged changes and last commit

combined. Use with nothing staged to edit the last commit’s message.

Rebase the current branch onto . can be a commit ID,

a branch name, a tag, or a relative reference to HEAD.

Git Basics Rewriting Git History

Git Cheat Sheet

Visit atlassian.com/git for more information, training, and tutorials

git config --global user.name

Define the author name to be used for all commits by the current user.

git config git config --global user.email

Define the author email to be used for all commits by the current user.

git config --global alias. <alias-name> <git-command>

Create shortcut for a Git command. E.g. alias.glog log --graph

--oneline will set git glog equivalent to git log --graph --oneline.

git config --system core.editor

Set text editor used by commands for all users on the machine.

arg should be the command that launches the desired editor (e.g., vi).

git config Open the global configuration file in a text editor for manual editing.

--global --edit

Limit number of commits by . E.g. git log -5 will limit to 5

commits.

git log -

Include which files were altered and the relative number of lines

that were added or deleted from each of them.

git log --oneline

Display the full diff of each commit.

git log --stat

Search for commits by a particular author.

git log -p git log --author= ”

Show commits that occur between and . Args can be a

commit ID, branch name, HEAD, or any other kind of revision reference.

git log --grep=”” git log ..

git log -- Only display commits that have the specified file.

--graph flag draws a text based graph of commits on left side of commit

msgs. --decorate adds names of branches or tags of commits shown.

git log --graph --decorate

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

git diff --cached Show difference between staged changes and last commit

git reset Reset staging area to match most recent commit, but leave the

working directory unchanged.

git reset --hard Reset staging area and working directory to match most recent

commit and overwrites all changes in the working directory.

git reset Move the current branch tip backward to , reset the

staging area to match, but leave the working directory alone.

git reset --hard

Same as previous, but resets both the staging area & working directory to

match. Deletes uncommitted changes, and all commits after .

git reset git rebase git rebase -i

Interactively rebase current branch onto . Launches editor to enter

commands for how each commit will be transferred to the new base.

git pull git pull --rebase

Fetch the remote’s copy of current branch and rebases it into the local

copy. Uses git rebase instead of merge to integrate the branches.

git push git push --force

Forces the git push even if it results in a non-fast-forward merge. Do not use

the --force flag unless you’re absolutely sure you know what you’re doing.

git push --all

Push all of your local branches to the specified remote.

git push --tags

Tags aren’t automatically pushed when you push a branch or use the

--all flag. The --tags flag sends all of your local tags to the remote repo.

Additional Options + Visit atlassian.com/git for more information, training, and tutorials git diff git log

Condense each commit to a single line.

Search for commits with a commit message that matches .