Version Control in the Command Line
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
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.
C1
C2
C3
C4
time
Imagine the 4th version of this file contains an error.
C1
C2
C3
time
With version control we can roll that change back to the previous working version.
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
We just initialized a git repository. What is this thing?
# 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
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
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
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.
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
Lets walk through creating a new public remote repository on github!
www.github.com
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.
Clean Socks!
Clean Socks!
$ git add socks
Clean Socks!
$ git commit
Clean Socks!
$ git push
Clean Socks!