0% found this document useful (0 votes)
12 views2 pages

2023_01_07 - mike-zr_git-and-github

This document is a cheat sheet for Git and GitHub, providing essential commands for starting a repository, staging and committing changes, managing branches, and handling tags. It includes commands for initializing repositories, checking status, merging branches, and pushing tags to remote repositories. The cheat sheet serves as a quick reference for users to efficiently navigate Git and GitHub functionalities.

Uploaded by

atmichael725
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)
12 views2 pages

2023_01_07 - mike-zr_git-and-github

This document is a cheat sheet for Git and GitHub, providing essential commands for starting a repository, staging and committing changes, managing branches, and handling tags. It includes commands for initializing repositories, checking status, merging branches, and pushing tags to remote repositories. The cheat sheet serves as a quick reference for users to efficiently navigate Git and GitHub functionalities.

Uploaded by

atmichael725
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/ 2

Git & GitHub Cheat Sheet

by mike-zr via cheatography.com/123658/cs/23379/

Starting A Repo Staging And Committing Inform​ation Differ​ences (cont)


(cont)
git init git status Opens the configured diff tool
Initia​lizes a Git repo in current Undoes changes made to <fi​le>, Returns the status of file (e.g. P4Merge) and shows the
directory. reverting back to last known changes, as well as new files. differ​ences between two
state of <fi​le> in the repo. commits (one of the commit id's
git init <fo​lde​r> git log
can be HEAD).
Initia​lizes a Git repo in <fo​lde​r> 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 <fi​le> <new name>
lde​r> if it doesn't exist. git show the diff.
Stages the renaming of <fi​le>.
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 <fi​le> Q to get out of show command) git branch
git add -u
Adds <fi​le> 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 change​s/a​ddi​tions
Lists all branches, including
and deletions. In effect also Differ​ences
git commit -m "​<commit remotes, and shows which one
stages renaming of files.
messag​e>" git diff you're currently on.
(git add . does almost the same
Commits files in staging area Shows the difference between git checkout <br​anc​h>
thing, read more HERE and
with a commit message. what's recently changed in the
HERE.) Switches to <br​anc​h>.
git commit working directory versus the
git rm <fi​le> git checkout -b <br​anc​h>
HEAD position in the repo
Opens Git's default editor to
Stages the deletion of <fi​le>. (which is usually the last commit Creates a new <br​anc​h> 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 <br​anc​h>
commit files in staging area with git difftool
Using Git to rename and delete Merges <br​anc​h> 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 automa​tically committing will complete the
messag​e>" 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 merget​ool
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 <fi​le>
Shows the differ​ences between
Removes <fi​le> from staging
two commits (one of the commit
area.
id's can be HEAD).
git checkout -- <fi​le>
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 lightw​eight tag at the repo to the remote repo. Git goes out to the remote repo
current commit. git push <remote ref> :<t​ag> and updates its local inform​ation
git tag <tag name> <br​anc​h> Tells GitHub to delete the tag about what's in the remote repo.

Creates a lightw​eight tag at the after the colon. git fetch -p <remote url>
last commit on <br​anc​h>. Git looks for any dead branches
Remote Repos and removes those refere​nces.
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>
not​ati​on>​" 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 conven​tio​nally
not​ati​on>​" <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 <ta​g> 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 <ta​g>, and
repo.
the annotation if there is one.
git clone <remote url>
git tag -f <ta​g> <commit id>
Clones the remote repo into the
Updates <ta​g> 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> <na​me>
(usually the last commit).
Clones the remote repo into the
git push <remote ref> <ta​g>
current directory in a new folder
Pushes the tag to the remote
named <na​me>. (Git labels this
repo.
remote as origin by default.)
git push --force <remote ref>
<ta​g>
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

You might also like