GIT Flashcards
What are the three states of GIT?
Working directory
Staging area
Commit - Repository (.git file) - history of changes
—–You could consider a fourth state
Remote repository
How do you configure you user name?
git config –global user.name “user name”
How do you configure your email address?
git config –global user.email “myemail@foobar.com”
How do you get the settings for your git user?
git config –global –list
What is the default branch?
master
How do you clone a repository?
git clone [repository link]
What is an untracked file?
Simply a file that hasn’t been added to a repository as yet.
How do you add an untracked file to the staging area?
git add [pathtofile]
How do you see what the current status of your repository is?
git status
If you commit a file using commit -m, what will the state of the working directory and the staging area be?
The working directory will be clean, and the staging area will have nothing to commit. By using git commit - you have committed the files to the repository. The third git state.
NOTE: Until you push the files to the remote repository - they are still local to your machine.
The remote name of the repository usually defaults to ‘origin’ - when is this created?
When you clone the repository.
How do you push a file to the remote repository (assuming you are using the default remote repository name, and master branch)?
git push origin master
How do you create a new GIT project locally (no source)?
git init [name of project]
When you do a commit - if you see the status:
[master (root-commit)]
What does this mean?
It’s the very first commit.
How do you create a new git repository based on existing source?
git init
From within the folder containing the source
How do you add all the files within a directory so that git is tracking them, in one command?
git add .
How do you stop a folder being tracked by git?
rm -rf .git
The .git file is the one inside the folder
The unique identifier (used for commits) is what kind of hash?
sha1
If you fork a repository - your git repository (on github) is upstream or downstream?
The fork is downstream - the original is upstream.
Is commit a local or a remote command?
local
Before doing a push - what should we do as a best practice?
git pull origin master
Make sure our local repository is up to date with the head.
When you do a push - you may get a response back that looks like this:
4beb7f0..cec9347 master - master
What does it mean?
The 4beb7f0..cec9347 are sha1 hashes that refer to the commit id’s. The left hand number is the local - the right hand number is the remote.
master - master, refers to the branch names, local master to remote master.
How do you add and commit a file at the same time?
git commit -am “Adding more text”
NOTE: This can only work with files that are being tracked.
What constitutes a tracked file?
Pretty much any state - with the exception of new files. So in staging, in the repository, editing existing file - are all tracked files.
New files have yet to be tracked, unless you use git add - filename.