Git Flashcards
What am I going to learn?
Everything I need to know to use Git like a pro
Work effectively with others
Fundamental concepts
Creating snapshots of code
browsing project history
collaborating using Github
rewriting history
What is Git and why is it popular?
Hint: track history, work together

most popular version control system in the world
More than 90% of software projects globally use Git
Almost every job description for software developer mentions Git
records changes made to code over time in a repository
can look at project history to see who made which changes when
can revert project back to earlier state

What is a centralized version control system?
All team members connect to central server to get latest code + share code
Problems?
Single point of failure
if server goes down, cannot collaborate
must wait for server to go back up to work together and save snapshots of code

What is a de-centralized version control system?
every team member has a copy of the project with it’s history on their machine
we can save snapshots of the project locally, on our machine
if server is offline, can synchronize directly with others
What must be in your toolbox if you want to get hired as a software developer?
Know the in’s and out’s of Git
How it works
How to track project history
How to work together effectively
How can we use Git?
Command line
fastest way, many people use
this course will focus on command line
Code Editors and IDEs
built in support for Git features w/ plugins for special features (GitLens, VS code, etc.)
Graphical user interfaces
tools for windows, mac, windows, Linux
GitKraken (GUI for Git) integrates with GitKraken boards (error tracking), timelines (project roadmaps)
have limitations, not always available
What are the different levels we can config Git?
System - all users
Global - all repos of the current user
Local - current repo
We can have different settings for different projects or repositories

What settings do we need to specify?
Name, Email, Default Editor
Line Ending (auto.crlf)

Why do we have to handle “end of line” settings properly?

Windows and Mac have different end of line characters
If we don’t setup line ending properly, will end up with issues down the road
Solution?
Configure variable corecrlf (carriage return line feed)
Windows Users (Git)
remove carriage return line characters (check into repo)
add carriage return line characters (check out repo)
Mac Users
don’t add carriage return characters
remove carraige return line characters if present before (check into repo)
Input - only modify end of lines, when storing into repository

How do we create a new repository?
Commands
$mkdir RepoName
$cd RepoName
$git init
Under the Hood
(implementation detail)
creates a .git file w/in directory (hidden)
.git file stores info about our project
project history, branches, hooks, objects, info, references
purely implementation details
don’t corrupt this file (will lose project history)

What is the git workflow?

Working Directory (Project Directory)
local to my machine
Index (Staging area)
.add command
intermediate step
review code before commit
Git Repository
subdirectory (hidden) in working directory

What does each commit contain?
Hint: complete snapshot
each commit contains…
a unique identifier
generated by git
information about change
Message
Date/Time
Author
complete snapshot of project (not only changes)
can revert to earlier version quickly without computing changes

What is the echo command?
A standard Unix / Linux command for writing content to a file
echo hello > file1.txt

What does $git status show us?
see status of working directory or staging area

How do we add files to staging area?
git add * .txt
all files with .txt ending
git add file1.txt file2.txt
multiple files separated by space
git add .
adds all files in current directory
beware some files we don’t want to add (.gitignore)

If we stage a file, then make a change locally, what must we do?
$git add fileName.ext
add to staging area again
Why?
Git stores a snapshot of file when $git add . to staging area

How do we store our snapshot permanently in our git repository?
$git commit -m “meaningful snapshot description”
bug constraints explained

What are best practice guidlines for commits?

whole point of commits is to record checkpoints
if a mistake is made, can go back to last checkpoint
each commit represents a single unit of work
DO LIST
commit often (5-10 times per day, depending on work)
commit at each checkpoint
As I reach a state I want to record, THEN make a commit
each commit should represent a logically chained step
give each commit message a meaningful comment (messages show in history)
Use present tense in commit message
DO NOT DO
make a commit everytime a file is updated
wait three days, then make a commit
build a feature end to end before making a commit
Do not wait until BIG commit to make a commit
commit two logical steps together
Ex. don’t commit bug fix / typo fix together (separate these)
How do we skip staging?
99% of time, stage code before commiting
Beware (only due if sure, don’t need to review)
-a all
-m message
$git commit -am
How do we remove a file from working directory?
Hint: remove from working directory,
.add + commit to remove from staging directory
$rm file2.txt
linux cmmd removes from working directory
still in staging directory (ls)
Soln?
Must stage changes using add command
$git add file2.txt
stages deletion
$git commit -m

How do we remove a file from working directory and staging files?
$git rm file2.txt
How do we move or rename files?
Hint: $git mv newFileName oldFileName
$ mv file1.txt main.js
rename file1.txt to main.js
Two step process:
- Modify working directory
- Stages two changes (add / delete)
$git mv
does this for us vs. standard unix command
changes are applied to both working directory and staging directory
$git commit -m

How do we ignore files?

certain files we want to ignore:
log files: individual for each developer, don’t want to include
node_modules: increase size of code, etc.
Solution?
Don’t want to add to staging area, don’t want git to track these
.gitignore (in root of project)
Beware?
If you accidentally add a file to your repository
THEN, add to gitignore, it won’t work
How do we remove a file from the staging area that we don’t want git to track?
must remove from staging area (index)
$git rm
removes from working directory and staging area
$git rm –cached -r bin/
removes only from staging area (index)



























































































































































