Skip to content

A "cheatsheet" for the Udacity course: How to Use Git and GitHub

Notifications You must be signed in to change notification settings

AnthonyMedina/Udacity-Git-Cheatsheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 

Repository files navigation

Udacity-Git-Cheatsheet

This is a "cheat sheet" of all the Git commands used in the Udacity course: How to Use Git and GitHub.

Some Useful Console Commands

Command Description Options
cd <directory path> "change directory" -
changes the folder you are operating in.
~ - to home directory
../ - up one folder
mkdir <folder name> "make directory" -
creates a new folder.
pwd "print working directory" -
displays the file path of the folder you are working in.
ls "list" -
lists files and folders in the folder you are working in
-a - list hidden files too
touch <filename> creates a new file
rm <filename> deletes a file
mv <filename> <target folder name> moves a file

Setting Up Your Workspace

  • Save this file in your home directory with the name git-completion.bash.
  • Save this file in your home directory with the name git-prompt.sh.
  • Download bash_profile_course here. If you already have a file in your home directory named .bash_profile, copy the content from bash_profile_course and paste it at the bottom of .bash_profile. Otherwise, move bash_profile_course to your home directory and rename it to .bash_profile.
Making Git Configurations

Run the following Git configuration commands. The first one will need to be modified if you are using a text editor other than Atom. See this page for the correct command for a couple of other popular text editors.

git config --global core.editor "atom --wait"
git config --global push.default upstream
git config --global merge.conflictstyle diff3

Lesson 1 - Navigating a Commit History

Command Description Options
git help Prints the synopsis and a list of the most commonly used commands -a prints all commands
git clone <repo-url> Clone a repository into a new directory directory - create a new folder for the clone
git log Show commit history --oneline - display on one line
--graph - show a graph of the branch, merge history
-<n> - show n commits
--stat - shows number of files changed, plus deletions and insertions for each commit
git diff Show changes between commits, commit and working tree, etc (no arguments) - view the changes you made relative to the index
--staged - view the changes you staged for the next commit relative to the latest commit
<commit1> <commit2> - compare two commits
git checkout <branch-name> Switch branches or restore working tree files -b <new-branch-name> - create and switch to new branch

Lesson 2 - Creating and Modifying a Repository

Command Description Options
git init Create an empty Git repository
git status Show the working tree status
git add <filename> Add file contents to the index
git commit Record changes to the repository -m - add message in terminal
-a - automatically stage files that have been modified and deleted
git reset Reset current HEAD to the specified state HEAD <filename - unstage file
git branch List, create, or delete branches <branch-name> - switch to branch
-d <branch-name> - delete branch
git merge <branch1> <branch2> Join two or more development histories together --abort - abort merge if there are unexpected conflicts
git show <commit-ID> Show various types of objects

Lesson 3 - Using GitHub to Collaborate

Set up Password Caching

Check that Git and the osxkeychain helper are already installed:

git credential-osxkeychain

Tell Git to use osxkeychain helper using the global credential.helper config:

git config --global credential.helper osxkeychain

Command Description Options
git remote Manage set of tracked repositories add <url> - add new remote
git push <remote> <branch> Fetch from and integrate with another repository or a local branch
git pull <remote> <branch> Update remote refs along with associated objects
git fetch Download objects and refs from another repository

About

A "cheatsheet" for the Udacity course: How to Use Git and GitHub

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published