Git & GitHub Cheat Sheet
by mike-zr via cheatography.com/123658/cs/23379/
Starting A Repo Staging And Committing Information Differences (cont)
(cont)
git init git status Opens the configured diff tool
Initializes a Git repo in current Undoes changes made to <file>, Returns the status of file (e.g. P4Merge) and shows the
directory. reverting back to last known changes, as well as new files. differences between two
state of <file> in the repo. commits (one of the commit id's
git init <folder> git log
can be HEAD).
Initializes a Git repo in <folder> Returns all commits that are a
Renaming And Deleting Files In P4Merge press Ctrl+Q to
in current directory. Creates <fo‐ part of the repo.
cycle to the next file involved in
git mv <file> <new name>
lder> if it doesn't exist. git show the diff.
Stages the renaming of <file>.
Returns the last commit with a
Staging And Committing The renaming takes place once
diff of the changes made. (Press Branching And Merging
committed.
git add <file> Q to get out of show command) git branch
git add -u
Adds <file> to staging area. git ls-files Lists local branches and shows
Stages deletions.
git add . Returns what files Git is which one you're currently on.
git add -A
Adds all files in current directory tracking. git branch -a
to staging area. Stages both changes/additions
Lists all branches, including
and deletions. In effect also Differences
git commit -m "<commit remotes, and shows which one
stages renaming of files.
message>" git diff you're currently on.
(git add . does almost the same
Commits files in staging area Shows the difference between git checkout <branch>
thing, read more HERE and
with a commit message. what's recently changed in the
HERE.) Switches to <branch>.
git commit working directory versus the
git rm <file> git checkout -b <branch>
HEAD position in the repo
Opens Git's default editor to
Stages the deletion of <file>. (which is usually the last commit Creates a new <branch> then
write a commit message (can be
Committing will complete the on the branch). switches to it.
multi-line). Save and exit to
deletion. git merge <branch>
commit files in staging area with git difftool
Using Git to rename and delete Merges <branch> into the
the commit message. Opens the configured diff tool
files (as opposed to using the current branch. If there are
Ctrl+W=exit (e.g. P4Merge), and shows the
operating system GUI) gives the conflicts, resolving them and
git commit -am "<commit difference between what's
benefit of Git automatically committing will complete the
message>" recently changed in the working
tracking the renaming and merge.
directory versus the HEAD
Adds modified files to staging deleting. If you rename a file
position in the repo (which is git mergetool
area and commits them. outside of Git, it will see the file
usually the last commit on the While in a merging state, opens
(Omitting the -m flag will open as being deleted along with a
branch). the configured merge tool (e.g.
default editor for commit new untracked file with the new
message.) git diff <commit id A> P4Merge).
name.
<commit id B>
git reset HEAD <file>
Shows the differences between
Removes <file> from staging
two commits (one of the commit
area.
id's can be HEAD).
git checkout -- <file>
git difftool <commit id A>
<commit id B>
By mike-zr Not published yet. Sponsored by Readable.com
cheatography.com/mike-zr/ Last updated 19th June, 2020. Measure your website readability!
Page 1 of 2. https://readable.com
Git & GitHub Cheat Sheet
by mike-zr via cheatography.com/123658/cs/23379/
Tags Tags (cont) Fetching And Pulling
git tag <tag name> Pushes all the tags in the local git fetch <remote url>
Creates a lightweight tag at the repo to the remote repo. Git goes out to the remote repo
current commit. git push <remote ref> :<tag> and updates its local information
git tag <tag name> <branch> Tells GitHub to delete the tag about what's in the remote repo.
Creates a lightweight tag at the after the colon. git fetch -p <remote url>
last commit on <branch>. Git looks for any dead branches
Remote Repos and removes those references.
git tag -d <tag name>
git remote -v The -p stands for prune.
Deletes the tag.
Lists remote repos. git pull <remote url> <local
git tag -a <tag name> -m "<an‐
branch name>
notation>" git remote add <remote ref>
<remote url> Checks for changes in the
Creates an annotated tag at the
remote repo, and pulls any
current commit. Adds reference to a remote
changes to your local branch. It
repo. <remote ref> can be
git tag -a <tag name> -m "<an‐
will open a commit window with
anything, but is conventionally
notation>" <commit id>
a default commit message you
called origin.
Creates an annotated tag at the can use. Will enter a merge
git remote set-url <remote
specified commit. state if there are conflicts.
ref> <remote url>
git tag --list git pull is actually a 2-in-1
Updates the URL for the remote
Lists tags. command: fetch then merge. It
reference.
git show <tag> first fetches the updates from the
git remote show <remote ref>
remote repo, then merges those
Shows the details of the commit
Returns info about the remote changes into the local repo.
associated with the <tag>, and
repo.
the annotation if there is one.
git clone <remote url>
git tag -f <tag> <commit id>
Clones the remote repo into the
Updates <tag> to be associated
current directory inside a new
with the specified commit.
folder that has the same name
Omitting <commit id> will
as the remote repo. (Git labels
associate the tag with where
this remote as origin by default.)
HEAD is on the current branch
git clone <remote url> <name>
(usually the last commit).
Clones the remote repo into the
git push <remote ref> <tag>
current directory in a new folder
Pushes the tag to the remote
named <name>. (Git labels this
repo.
remote as origin by default.)
git push --force <remote ref>
<tag>
Forces the push of the updated
tag.
git push <remote ref> --tags
By mike-zr Not published yet. Sponsored by Readable.com
cheatography.com/mike-zr/ Last updated 19th June, 2020. Measure your website readability!
Page 2 of 2. https://readable.com