git
Version Control in the Command Line
Objectives
- Define "Version Control"
- Define crucial git vocabulary words
- repository
- staged / unstaged
- commit / history
- Use git from the command line
- git init
- git add
- git commit
- git push
Objectives
- Define "Version Control"
- Define crucial git vocabulary words
- repository
- staged / unstaged
- commit / history
- remote
- Use git from the command line
- git init
- git add
- git commit
- git push
Version Control
Version control is a term used to track and manage changes to a "codebase" over time.
For now, imagine a single file called C:
C1
C2
C3
C4
time
Version Control
C1
C2
C3
C4
time
With version control, we can view the differences between this file at different time points. This helps us understand the history of a codebase.
Version Control
C1
C2
C3
C4
time
Imagine the 4th version of this file contains an error.
Version Control
C1
C2
C3
time
With version control we can roll that change back to the previous working version.
Version Control
- Define "Version Control"
-
Define crucial git vocabulary words
- repository
- staged / unstaged
- commit / history
- remote
-
Use git from the command line
- git init
- git add
- git commit
- git push
Repositories
Lets create a situation like this now.
Make a directory and use git to make it a git repository.
$ cd ~/Desktop
$ mkdir tmp
$ cd tmp
$ git init
$ git status
Repositories
We just initialized a git repository. What is this thing?
- Repositories are folders.
- Everything inside this folder is under "version control" now, managed by git
# Try this:
$ ls -la
drwxr-xr-x 3 Tyler staff 102 Apr 14 16:01 .
drwx------+ 19 Tyler staff 646 Apr 14 16:00 ..
drwxr-xr-x 10 Tyler staff 340 Apr 14 16:01 .git # WHAT IS THIS?!
$ cd .git
$ tree
Repositories
That folder named .git is a hidden folder
That folder contains the history information for this repository.
Try this:
$ rm -r .git
$ git status
Without a .git folder, we don't have a repo
Repositories
- Define "Version Control"
- Define crucial git vocabulary words
- repository
- staged / unstaged
- commit / history
- remote
- Use git from the command line
- git init
- git add
- git commit
- git push
Repositories
Reinitialize our folder to be a repository and make a javascript file
$ git init
$ touch helloWorld.js
$ git status
Now we want to "stage" our changes for the a "commit"
$ git add helloWorld.js
$ git status
Repositories
- Define "Version Control"
- Define crucial git vocabulary words
- repository
- staged / unstaged
- commit / history
- remote
- Use git from the command line
- git init
- git add
- git commit
- git push
Repositories
The final step in creating a "version" is to use the commit command
$ git commit -m "Useful message"
$ git status
$ git log
Now this commit is part of our history, which we can view with the git log command.
Remotes
- Define "Version Control"
- Define crucial git vocabulary words
- repository
- staged / unstaged
- commit / history
- remote
- Use git from the command line
- git init
- git add
- git commit
- git push
Remotes
So far, our history lives in that .git folder.
We'd like to use the internet to backup our work, as well as share our work with collaborators!
Enter: GitHub
Remotes
Lets walk through creating a new public remote repository on github!
www.github.com
A Metaphor
As we've seen, in git changes roll through several stages
A useful metaphor is to imagine git as a rocketship, and github as mars.
Mars Needs Supplies
Clean Socks!
Mars Needs Supplies
Clean Socks!
$ git add socks
Mars Needs Supplies
Clean Socks!
$ git commit
Mars Needs Supplies
Clean Socks!
$ git push
Mars Needs Supplies
Clean Socks!
Just The Start
- At Galvanize, and at work, you will use git literally every day.
- It's a big, complex, powerful tool. You can (and should) become a power user.
- (incrementally)
Questions?
Git
By Tyler Bettilyon
Git
- 1,415