Made by your boy



Made by your boy

0 1


gitCheatSheet

Quick command line + git cheatsheet (super simple, for beginners)

On Github FEWDMaterials / gitCheatSheet

Command Line Cheatsheet

Handy Terminal Commands

(Arrow or scroll down to see)

pwd

Shows current working directory

ls

Shows current folders/files within current working directory

ls -al

Shows all current folders / files in list form

cd [DIRETORY_PATH]

Changes the present working directory to the one specified.

cd ~

Takes you back "home" no matter where you are, this is usually the folder that contains your Documents, Desktop, etc

cd ../

Changes directory to one above your present working directory. Similarly, ../../ goes up two directories above present working directory, etc

mkdir [directory_name]

Creates a directory.

rm -rf [directory_name]

(This will remove the folder FOREVER and cannot be recovered)

Removes a FOLDER and everything inside of it (including other folders).

touch filename.js

Creates an empty file (you can edit it in Sublime Text)

rm filename.js

Removes a file called filename.js. Note this must be in your present working directory. Also note that we do not need -rf arguments here

Why Git?

Git will keep track of the files as you code. Remember that one time in college when you wrote the perfect sentence?

But then fate cruelly killed the battery on your laptop before you had a chance to save?

And that sentence -- in its perfection -- was lost to both you and mankind for all eternity? (Because Cmd+Z cannot help you once the text editor is closed). (But also the world just wasn't ready for such literary genius).

Well, if you had git commited + pushed your paper with that sentence immediately after crafting it -- then went on to write a completely different paper on that same file and burning your computer in a large bonfire...

...you would still have that sentence of yours!

Perfectly intact.

Along with whatever your wrote before it.

Even though the computer you wrote it on is now burned to a crisp and that file now hosts an elaborate list of movies you want to watch before turning 25...

Git is simply a software that allows us have these safeguards for the code we write.

GitHub is a website that allows us to save our git repositories (folders that are tracked by git) in the cloud.

Commiting to Git

First, navigate to the folder you want to start watching with Git

git init

This will start tracking all the files that change in your present working directory

git status

This is your best friend, it will tell you what start each file in your directory is in

git add [file_name]

You git add files that you want to be "frozen" into the current git revision. Typically, a git revision will have several files earmarked to be "frozen" (because a website feature is typically some html changed, some css changes, some javascript changes all at once).

git commit -m "commit message"

(-- make it something succint that describes your changes)

Once all the files that have changed are earmarked to be frozen, you run a git commit with a message. This will create a snapshot of your code AS IT IS NOW so you can go back to it later if you ever need to.

Pushing to GitHub

Ok! So you've a few commits under your belt now.

Great!

...Now what?

Get your GitHub on!

First, create an account on GitHub. (Or, sign in if you already have one).

Create a new repo

On the top right hand bar, there is a '+' button. Click that and create a new repository.

Do you see this?

Copy and paste your two lines

...into your terminal window.

Make sure your present working directory is the one that has a .git folder. You can do ls -al to confirm

That's it!

You should be solid. Every few commits, do yourself a favor and push to github. After the first push, all you need to do is:

git push

(the -u origin master is no longer needed).

If you want to host your project on GitHub, check out this tool I made.

Laugh all the way to the bank.

Made by your boy

Command Line Cheatsheet