Git Flashcards
What is the Git directory?
Where Git stores the metadata and object database for your project.
What is copied when you clone a repository from another computer
What is a working directory?
A single checkout (co) of one version of the project
Pulled from the Git directory to be used or modified
What is a staging area?
a file, generally contained on your Git directory, that stores information about what will go into your next commit
Also referred to as the index
Git Workflow
1- Modify files in your working directory
2- Stage the files - adding snapshots of them to your staging area
3- Do a commit which takes the files as they are in the staging area and stores the snapshot permanently to your Git directory
States:
1- committed - it is in the Git directory
2- modified - has been changed since it was checked out but has not been staged
3- staged - has been modified and added to the staging area
The 3 main sections of a Git project
1- The Git directory
2- The working directory
3- The staging area
How do you create a new git repository from an existing project?
Go to the project directory and type
git init
what does git init do?
creates a new subdirectory called .git
that contains a git repository skeleton
How do you get a copy of an existing git repository?
git clone [url]
what are the possible states that a file in your working directory can be in?
- tracked
- untracked
What are tracked files?
files that were in the last snapshot
What states can tracked files be in?
- unmodified
- modified
- staged
what are untracked files?
anything in your working directory that were not in your last snapshot and are not in your staging area
when you first clone a repository, in what state are all of the files?
tracked and unmodified
how do you determine which files are in which state?
git status
what is meant by “working directory clean”?
no tracked and modified files
what is an untracked file?
a files that was not in the previous snapshot (commit) and has not been “added” using git add
how do you know that a file is staged
git status
shows it as “changed to be committed”
what is
git add
used for?
1-to begin tracking new files
2-to stage files
3-marking merge conflicted files as resolved
you can think of it as: “add this content to the next commit” or “stage this file”
what are the two columns in short status
status -s
1- the first column indicates whether the file is staged
2- the second column indicates whether it has been modified
short name for a git repository
repo
How do you initialize a new git repo?
git init
how do you add all of the project files to the current git repo?
$ git add -A
- this adds the files to the git staging area
- adds all of the files in the current directory except those that match the patterns in a file called .gitignore
what command will tell you all of the files in the staging areaz/
$ git status
How do you tell git to keep the changes in the staging area?
$ git commit -m “initialize repository”
(use the-m flag to add a message -some current tense name)
-if you omit -m, git will open the system’s default text editor and have you enter the message there
-note: git commits are local on the machine on which the commit occurs
How do you push changes to a remote repository?
$ git push
how do you get a list of your commit messages?
$ git log
bitbucket
- a site optimized for hosting and sharing git repositories
- this makes a full backup of your code
- makes the code available for sharing
what is a branch?
- a copy of the entire repository
- usually the parent repository is the master branch
How do you create a new branch?
-a branch is a copy of the complete repository where you can make changes without modifying the parent files
$ git checkout -b modify-Readme
-this switched to a new branch called ‘modify-README’
how do you add bitbucket as the origin for your repository and then push your repository up to the remote origin?
$ git remote add origin git@bitbucket.org:smartinconsult/hello_app.git
$ git push -u origin –all
this pushes up the repo and its refs for the first time
Ruby tutorial p. 36
how do you see a list of branches that you have?
$ git branch
lists all the local branches and identifies the current branch with an asterisk