Basic Git Workflow Flashcards
Explain the following:
git init
The word init means initialize. The command sets up all the tools Git needs to begin tracking changes made to the project
creates a new Git repository
How can you think of a Git project?
A Git project can be thought of as having three parts:
- A Working Directory: where you’ll be doing all the work: creating, editing, deleting and organizing files
- A Staging Area: where you’ll list changes you make to the working directory
- A Repository: where Git permanently stores those changes as different versions of the project
The Git workflow consists of editing files in the working directory, adding files to the staging area, and saving changes to a Git repository. In Git, we save changes with a commit
Explain following:
git status
When you do work, you will be changing contents of the working directory. You can check the status of these changes with
git status
inspects the contents of the working directory and staging area
What does the
untracked filesstand for?
n the output, notice the file in red under
untracked files. Untracked means that Git sees the file but has not started tracking changes yet.
Explain the following
git add filename
In order to Git to start tracking a file, the file needs to be added to the staging area.
The file shows up as green colored when it is added to staging area.
adds files from the working directory to the staging area
Explain the following:
git diff filename
When you make changes in a file after you added it, since the file is tracked, we can check the differences between the working directory and the staging area with
git diff filename
shows the difference between the working directory and the staging area
Explain the following
git commit
A commit is the last step in our Git workflow. A commit permanently stores changes from the staging area inside the repository.
You need the
-moption followed by a message, as so:
git commit -m "Complete first line of dialogue"
Standard convention for commit messages:
1. Must be in quotation marks
2. written in present tense
3. Should be brief (50 characters or less) when using
-m
permanently stores file changes from the staging area in the repository
Explain the following
git log
Often with Git, you’ll need to refer back to an earlier version of a project. Commits are stored chronologically in the repository and can be viewed with:
git log
shows a list of all previous commits
Explain the following
What is the purpose of Git’s staging area?
To stage file changes for a commit
The output below is typical of which command?
commit bda95786432d142bbff996ad32045fa4f32ec619 Author: codecademy <ccuser@codecademy.com> Date: on Nov 16 13:13:33 2015 -0500 First commit
git log
The command “git status” shows
Untracked files and file changes staged for commit
Explain the following:
git show HEAD
In Git, the commit you are currently on is known as the HEAD commit. In many cases, the most recently made commit is the HEAD commit.
The output of this command will display everything the git log command displays for the HEAD commit, plus all the file changes that were committed.
What does ‘git checkout’ do and how do you use it?
git checkout HEAD filename
will restore the file in your working directory to look exactly as it did when you last made a commit.
Here, filename again is the actual name of the file. If the file is named changes.txt, the command would be
git checkout HEAD changes.txt
How do you add multiple files to staging area?
git add filename_1 filename_2
What does this command do:
git reset HEAD filename
This command lets you unstage that file from the staging area. This command resets the file in the staging area to be the same as the HEAD commit. It does not discard file changes from the working directory, it just removes them from the staging area.
If you staged a file, but then you realize you do not want to commit that file to repository, then this command restores that file as it previously was in the HEAD commit.
Notice in the output, “Unstaged changes after reset.”
Mis short for “modification”