# print working directory$pwd# list contents of current directory$ls# list contents of <dir>$ls<dir># list all/hidden files$ls-a# take me to my home directory$cd# change directory to <dir name>$cd<dir># change to directory above$cd..# print file to your screen$cat<filename># make directory$mkdir<dir_name># delete a file$rm<filename># recursively delete a directory -- BE VERY CAREFUL WITH THIS COMMAND!!$rm-rf<directory-name># copy a file from its current directory to another directory location$cp<filename><directory-location># move a file from current directory to another directory location$mv<filename><directory-location># rename a file in current directory -- applies to filename or directory name$mv<oldname><newname># move & rename a file from current directory to directory above$mv<filename>../<new-filename># open up an in-terminal text editor (note the shortcuts along the bottom)$nano# edit a file$nano<filename>
Common vi commands
Git's default fallback editor is vi, a terminal text editor, similar to nano, but with a higher learning curve and more functionality.
Refer to various reference cards, such as this one.
It's important to know that vi has two modes: insertion and command. When you first start vi, editor is in command mode. "i" puts the editor in insertation mode, where you can type without triggering commands -- ESC returns the editor into command mode.
Common commands (in command mode):
# quit w/o saving -- <shift><:>:q!# save & quit:wq# change to insert modei# delete worddw
Common Git commands
We gave out a "Git Cheatsheet" at the beginning of the year that is very helpful. An online version can be found here.
# sets the name attached to commits - this should be your full namegitconfig--globaluser.name"name"# sets the email attached to commits - should be the email used for GitHubgitconfig--globaluser.email"email"# makes a new local repository with the specified namegitinit<projectname># downloads a repository in the current directorygitclone<url>.git# stages all modified files for commitgitadd.# commits all staged changes with a commit messagegitcommit-m"Commit message"# pushes all commited changes to the origin repositorygitpushoriginmaster# pulls all changes from the latest version of the codegitpullupstreammaster# fetches the latest commits without merging themgitfetch<repository><branch># gets rid of ALL your changes and resets the repository to upstream - use with EXTREME CAUTIONgitreset--hardupstream/master
How do I revert previous commit?
Sometimes you mess up, and don't realize it until after committing your changes.
Git makes it easy to revert your changes with use of the git reset command. Git reset lets you revert to a previous commit hash, which you have to find first with git log.
When your local repo is behind the repo you are pushing to you will see an error non-fast-forward updates were rejected. That means you need to retrieve the changes before you can push your changes. Read more about git pull vs git fetch and git merge.