Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Terminal Cheat Sheet
# Terminal Cheat Sheet
pwd # print working directory
ls # list files in directory
cd # change directory
~ # home directory
.. # up one directory
- # previous working directory
help # get help
-h # get help
--help # get help
man # manual
cat # output the contents of a file
mkdir # create new directory
open # open a file with the associated program, a directory with Finder, or a URL with the default web browser
ps # list all running processes
kill # terminate existing process
rmd # permanently delete file
rmdir # remove directory
## Working with Git
### Quick Start
git clone <url> # Clone directory
git checkout -b <new-branch> # Create new local branch
git push -u origin <new-branch> # Sync local branch with remote
git checkout <branch> # Checkout branch
git push origin <branch> # Push branch to remote
git branch -d <branchname> # deletes local branch
git push origin :<branchname> # deletes remote branch
git subtree push --prefix docs origin gh-pages # push docs as subtree to gh-pages
### Clone Directory
git clone <url>
### Create Project
cd project/
git init # initializes the repository
git add . # add those 'unknown' files
git commit # commit all changes, edit changelog entry
git rm --cached <file>... # ridiculously complicated command to undo, in case you forgot .gitignore
### Branching and Merging
git branch # show list of all branches (* is active)
git checkout -b linux-work # create a new branch named "linux-work"
<make changes>
git commit -a
git checkout master # go back to master branch
git merge linux-work # merge changesets from linux-work (Git >= 1.5)
git pull . linux-work # merge changesets from linux-work (all Git versions)
git branch -m <oldname> <newname> # rename branch
git branch -m <newname> # rename current branch
### Delete Project
git branch -d <branchname> # deletes local branch
git push origin :<branchname> # deletes remote branch
git remote prune <branchname> # update local/remote sync
### Merging Upstream
git remote -v # Get list of remote branches
git remote add upstream <upstream github url> # Add original as upstream
git remote -v # Check upstream
git fetch upstream # Get original repo
git checkout development # Switch to main branch in local fork
git merge upstream/development # Merge original with fork
git diff --name-only | uniq | xargs subl # Fix conflicts in Sublime Text
### Importing Patches
git apply < ../p/foo.patch
git commit -a
### Exporting Patches
<make changes>
git commit -a -m "commit message"
git format-patch HEAD^ # creates 0001-commit-message.txt
# (HEAD^ means every patch since one revision before the
# tip of the branch, also known as HEAD)
### Inspecting Revisions
# inspect history visually
gitk # this opens a Tk window, and shows you how the revisions are connected
# inspect history
git log # this pipes a log of the current branch into your PAGER
git log -p # ditto, but append a patch after each commit message
# inspect a specific commit
git show HEAD # show commit info, diffstat and patch
# of the tip of the current branch
### Referring to Revisions
# by name
git log v1.0.0 # show history leading up to tag "v1.0.0"
git log master # show history of branch "master"
# relative to a name
git show master^ # show parent to last revision of master
git show master~2 # show grand parent to tip of master
git show master~3 # show great grand parent to tip of master (you get the idea)
# by output of "git describe"
git show v1.4.4-g730996f # you get this string by calling "git describe"
# by hash (internally, all objects are identified by a hash)
git show f665776185ad074b236c00751d666da7d1977dbe
git show f665776 # a unique prefix is sufficient
# tag a revision
git tag v1.0.0 # make current HEAD known as "v1.0.0"
git tag interesting v1.4.4-g730996f # tag a specific revision (not HEAD)
### Comparing Revisions
# diff between two branches
git diff origin..master # pipes a diff into PAGER
git diff origin..master > my.patch # pipes a diff into my.patch
# get diffstat of uncommitted work
git diff --stat HEAD
## Sublime as default text editor
cd ~
mkdir bin
ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl
git config --global core.editor "subl -n -w"
### If that's not working
sudo rm -rf /usr/local/bin/subl
sudo ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/local/bin
@JohnYu500

This comment has been minimized.

Copy link

@JohnYu500 JohnYu500 commented Apr 17, 2019

Very helpful! Thanks!

@ahmaddev313

This comment has been minimized.

Copy link

@ahmaddev313 ahmaddev313 commented Aug 23, 2019

Nice... thank you!

@lgebremedhin

This comment has been minimized.

Copy link

@lgebremedhin lgebremedhin commented Aug 30, 2019

Very helpful, Thanks.

@triveni-prog

This comment has been minimized.

Copy link

@triveni-prog triveni-prog commented Sep 4, 2019

how to copy/store git tags into folder

@abduallahnoorsayket

This comment has been minimized.

Copy link

@abduallahnoorsayket abduallahnoorsayket commented Sep 9, 2019

Thanks a lot.

@dexterzep

This comment has been minimized.

Copy link

@dexterzep dexterzep commented Sep 17, 2019

isnt there a way to list all the contents of the remote repo (github in this case) like in svn we can do --->> svn list http://ip/location/of/file

@cferdinandi

This comment has been minimized.

Copy link
Owner Author

@cferdinandi cferdinandi commented Sep 17, 2019

@amaurybsouza

This comment has been minimized.

Copy link

@amaurybsouza amaurybsouza commented Oct 17, 2019

Nice, I needed to search a command and your list help me.

@Hariharanayalur

This comment has been minimized.

Copy link

@Hariharanayalur Hariharanayalur commented Nov 7, 2019

thank you its very resourceful

@Asadbe

This comment has been minimized.

Copy link

@Asadbe Asadbe commented Jan 28, 2020

ewinwe

@Asadbe

This comment has been minimized.

Copy link

@Asadbe Asadbe commented Jan 28, 2020

its difficult to me

@mrivasperez

This comment has been minimized.

Copy link

@mrivasperez mrivasperez commented Feb 18, 2020

Super useful! Thank you so much for creating this resource.

@yearmfew

This comment has been minimized.

Copy link

@yearmfew yearmfew commented Mar 13, 2020

this is very well prepared. Thank you. It really helped. I was always getting lost in websites while trying to remember some codes especially for github. It is reallt good summarized everything.

@gozeloglu

This comment has been minimized.

Copy link

@gozeloglu gozeloglu commented Mar 20, 2020

Awesome!

@saintlammy

This comment has been minimized.

Copy link

@saintlammy saintlammy commented Apr 11, 2020

Nice!
Helps a lot.

@derekgeorg

This comment has been minimized.

Copy link

@derekgeorg derekgeorg commented Apr 14, 2020

Love this. Thank you.

@georgekanage

This comment has been minimized.

Copy link

@georgekanage georgekanage commented May 2, 2020

Very useful. Thanks

@chidu1978

This comment has been minimized.

Copy link

@chidu1978 chidu1978 commented Jul 4, 2020

This is very very helpful, much appreciated. Thanks

@Fernando1729

This comment has been minimized.

Copy link

@Fernando1729 Fernando1729 commented Jul 7, 2020

GREAT!!!! Thank you soooo much! S2

@anissa1908

This comment has been minimized.

Copy link

@anissa1908 anissa1908 commented Jul 16, 2020

Thanks for sharing ! I really needed a comprehensive list.

@rnagel3

This comment has been minimized.

Copy link

@rnagel3 rnagel3 commented Jul 23, 2020

respect

@bjmacgreg

This comment has been minimized.

Copy link

@bjmacgreg bjmacgreg commented Jul 24, 2020

Thanks! My memory for commands is full... this helps a lot.

@WLewis69

This comment has been minimized.

Copy link

@WLewis69 WLewis69 commented Aug 10, 2020

Great reference to use with GitHub terminal within Android Studio!

@Yediyarov

This comment has been minimized.

Copy link

@Yediyarov Yediyarov commented Aug 14, 2020

Thanks!

@Kashish-pandita

This comment has been minimized.

Copy link

@Kashish-pandita Kashish-pandita commented Aug 24, 2020

Thank you Sir ! It is very helpful

@PappuKP

This comment has been minimized.

Copy link

@PappuKP PappuKP commented Aug 24, 2020

This is very very helpful, much appreciated. Thanks

@JennaScript

This comment has been minimized.

Copy link

@JennaScript JennaScript commented Sep 14, 2020

Legend! Thank you!

@emirate691

This comment has been minimized.

Copy link

@emirate691 emirate691 commented Dec 26, 2020

i was working on branch main, and i want to go back to origin master . how can i do that

@tjw-livongo

This comment has been minimized.

Copy link

@tjw-livongo tjw-livongo commented Dec 29, 2020

i was working on branch main, and i want to go back to origin master . how can i do that

@emirate691 git checkout master to get back to your latest pull of master branch, then git pull if you want to get all changes merged into master since your last pull.

@assmaratib

This comment has been minimized.

Copy link

@assmaratib assmaratib commented Dec 30, 2020

Very helpful, thanks

@efe-osa

This comment has been minimized.

Copy link

@efe-osa efe-osa commented Jan 6, 2021

This is perfect! Thank you for this

@VivianeBusch-Wallace

This comment has been minimized.

Copy link

@VivianeBusch-Wallace VivianeBusch-Wallace commented Feb 17, 2021

Super nice! Thank you!

@NatalineGn

This comment has been minimized.

Copy link

@NatalineGn NatalineGn commented Feb 20, 2021

Very useful, thank you🌟

@salamituns

This comment has been minimized.

Copy link

@salamituns salamituns commented Mar 19, 2021

Thanks, really!

@sipelo-mazwi

This comment has been minimized.

Copy link

@sipelo-mazwi sipelo-mazwi commented Apr 9, 2021

Thank you so much !!!!

@dominguezsantal

This comment has been minimized.

Copy link

@dominguezsantal dominguezsantal commented May 29, 2021

Awesome @cferdinandi, please don't forget to put the command to change the branch master to main and edit the parts that says master to main. I believe Github changed master to main in their commands recently.

@Tibzie

This comment has been minimized.

Copy link

@Tibzie Tibzie commented Jun 6, 2021

OMG! This is so useful! Thank you very much!!!

@wisyprim

This comment has been minimized.

Copy link

@wisyprim wisyprim commented Jun 6, 2021

Finally, the support i needed. Thanks

@tanujit

This comment has been minimized.

Copy link

@tanujit tanujit commented Jun 11, 2021

GG mah friend

@LoukasGP

This comment has been minimized.

Copy link

@LoukasGP LoukasGP commented Jun 11, 2021

Thank you!

@alphaion

This comment has been minimized.

Copy link

@alphaion alphaion commented Jun 12, 2021

Very helpful, thank you!

@mahak999

This comment has been minimized.

Copy link

@mahak999 mahak999 commented Jul 25, 2021

This is very helpful. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment