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.
How do you get a list of all files that are being tracked?
git ls-files
If you use git add filename - and then you edit that file name again and call git status - what will you see?
The same file will be listed twice, once as a new set of changes, and again as an existing file ready to commit. Despite the fact it’s one file - it will apear like two. By calling git add on the file, you are basically merging both changes into the staging area.
How do you add files recursively?
Adding files using “git add . “ will recursively add files (up through a folder structure).
Can you issue commands from anywhere within your git repository?
Yes - for most commands that’s fine.
How do you unstage a file?
So after using git add filename - you’ve decided it’s not ready for a commit, you want to do more work. You can back out of the staging area by calling
git reset HEAD filename
Does unstaging a file remove the changes?
No - it simply removes the file from the staging area, and returns it to the working directory.
How do you revert any changes made to a file in your working directory (i.e. trash the changes)?
git checkout – filename
NOTE: This discards and loses all changes
How do you rename a file?
You can rename using the git mv comand
git mv oldname newname
Then you simply commit the change. NOTE: Until you commit, you can easily backout the rename, like you would normally do (git reset HEAD filename)
OR
You can mv on the command line. BUT - git will see htis as a deletion and an addition. To fix this, you use
git add -A
This will update any files that have been renamed, moved or deleted on the filesystem. Once you have done this - git status will report it as a renamed file, and no longer as a deleted and added file.
Why should you rename your files before you make any changes?
Makes it easier for git to track the changes.