|
| 1 | +# Basics |
| 2 | + |
| 3 | +The [git book](https://git-scm.com/book) is a thorough and helpful introduction to installing and setting up git. |
| 4 | +Sections [1 Getting Started](https://git-scm.com/book/en/v2/Getting-Started-About-Version-Control) and [2 Git Basics](https://git-scm.com/book/en/v2/Git-Basics-Getting-a-Git-Repository) cover everything we expect plus a little extra. |
| 5 | +Below we review the commands we expect you to know, plus a summary of usage and a link to more information. |
| 6 | + |
| 7 | +<!-- START doctoc generated TOC please keep comment here to allow auto update --> |
| 8 | +<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> |
| 9 | + |
| 10 | + |
| 11 | +- [Create a new repo (`git init`)](#create-a-new-repo-git-init) |
| 12 | +- [Get an existing repo (`git clone`)](#get-an-existing-repo-git-clone) |
| 13 | +- [Stage changes for commit (`git add`)](#stage-changes-for-commit-git-add) |
| 14 | +- [Commit changes (`git commit`)](#commit-changes-git-commit) |
| 15 | +- [Push changes to remote (`git push`)](#push-changes-to-remote-git-push) |
| 16 | +- [Get updates (`git pull`)](#get-updates-git-pull) |
| 17 | +- [Check the current status (`git status`, `git diff`, `git diff --cached`)](#check-the-current-status-git-status-git-diff-git-diff---cached) |
| 18 | + |
| 19 | +<!-- END doctoc generated TOC please keep comment here to allow auto update --> |
| 20 | + |
| 21 | + |
| 22 | +## Create a new repo (`git init`) |
| 23 | + |
| 24 | +`git init` creates a new repository from a directory. |
| 25 | +For more details, see [initializing a repository in directory](https://git-scm.com/book/en/v2/Git-Basics-Getting-a-Git-Repository#Initializing-a-Repository-in-an-Existing-Directory). |
| 26 | + |
| 27 | + |
| 28 | +## Get an existing repo (`git clone`) |
| 29 | + |
| 30 | +`git clone` makes a local copy of someone else's repository. |
| 31 | +The other repository can be hosted anywhere - on Github, Gitlab, or someone else's computer. |
| 32 | +For more details see [cloning an existing repository](https://git-scm.com/book/en/v2/Git-Basics-Getting-a-Git-Repository#Cloning-an-Existing-Repository). |
| 33 | + |
| 34 | + |
| 35 | +## Stage changes for commit (`git add`) |
| 36 | + |
| 37 | +`git add` will tell git to track changes to a file. |
| 38 | +Adding a file also stages the changes made to that file for committing. |
| 39 | +The changes are not actually saved until `git commit` is run. |
| 40 | +For more details, see [tracking new files](https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository#Tracking-New-Files). |
| 41 | + |
| 42 | + |
| 43 | +## Commit changes (`git commit`) |
| 44 | + |
| 45 | +`git commit` saves the staged changes to git. |
| 46 | +A commit stores the name & email of the person who wrote it, the date the change was made, its parent, and the changes themselves. |
| 47 | +For more details, see [committing your changes](https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository#Committing-Your-Changes). |
| 48 | + |
| 49 | + |
| 50 | +## Push changes to remote (`git push`) |
| 51 | + |
| 52 | +`git push` sends all commits to someone else's repository. |
| 53 | +If you used `git clone`, by default they are sent to `origin`, which is the repository you cloned from. |
| 54 | +For more details, see [pushing to your remote](https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes#Pushing-to-Your-Remotes). |
| 55 | + |
| 56 | + |
| 57 | +## Get updates (`git pull`) |
| 58 | + |
| 59 | +`git pull` updates your local copy with changes from someone else's repository. |
| 60 | +If you used `git clone`, by default the changes are fetched from `origin`, which is the repository you cloned from. |
| 61 | +For more details, see [pulling from your remote](https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes#Fetching-and-Pulling-from-Your-Remotes). |
| 62 | + |
| 63 | + |
| 64 | +## Check the current status (`git status`, `git diff`, `git diff --cached`) |
| 65 | + |
| 66 | +`git status` shows what git currently knows about the files in the repository. |
| 67 | +It show what files git is tracking, what files have had changes, and what files have changes staged for commit. |
| 68 | +`git status` only shows the names of files. |
| 69 | +For more details, see [checking the status of your files](https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository#Checking-the-Status-of-Your-Files). |
| 70 | + |
| 71 | +`git diff` shows changes in file that git tracks that haven't been staged for comit. |
| 72 | +`git diff --cached` (also known as `git diff --staged`) shows changes to files that have been staged for commit. |
| 73 | +Both commands show the actual changes that happened in a file. |
| 74 | +For more details, see [viewing your changes](https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository#Viewing-Your-Staged-and-Unstaged-Changes). |
0 commit comments