Pre-work Part I: Let's Git Started

Pre-work Part I: Let's Git Started

##What is version control? Simple put, version control is collaborative history tracking. This means if a group of people are working on a project, be it software or otherwise they can use version control to track their progress and modifications without overwriting each other. One person changes a font, someone else changes a paragraph, yet another person adds an imbedded video. Without version control you would have to worry about one person overwriting another. However, with version control, all of your individual changes are recorded and can be merged together at a later date. For more information check out the video below. Several popular VCSs include Perforce, Subversion, CVS, Bazaar and of course Git.

##What is Git? Git is the most popular version control software around. It was invented by Linus Torvalds, inventor of Linux. Most other VCSs store information as a list of file-based changes. Git stores data as a series of snapshots. Almost every operation in Git is local meaning you don’t need to wait on a server. Most operations are instantaneous. Git snapshots are checksummed with a 40 character string of hexadecimal characters called a SHA-1 hash so its impossible to change the contents of a file or directory without Git knowing about it. Git really only adds data. It’s hard to erase data or do something undoable.

###Git Structure There are 3 states in Git: committed, modified, and staged. Committed means your data is stored in the database. Modified means you’ve made changes but they hacen’t been committed to the database yet. Staged means you’ve marked a file to be committed on your next commit snapshot.

There are 3 main elements to a Git project: the working directory, the staging area, and the .git directory (reposiitory). The Git directory, also known as the repository, is where your metadata and object database is stored. It’s the most important part of Git and it’s what gets copied when you clone a repository. The working directory is the area you’re working with when you’re making changes to your files. It’s a single checkout of one version of the project. The files are pulled out of the Git directory and placed here for you to use. The staging area is just a file that contains information about what will go into your commit.

git elements

###Basic Git workflow

  • Modify files in working directory
  • Stage files by adding a snapshot to the staging area
  • Commit, move the snapshot into your Git directory.

##Is it different from Github? Github is a free online Git repository. It offers a GUI and a graphical client for Mac and PC. A simple comparison is this

Git is to Github as email is to Gmail.

###Commands git init this means git initialize, running this command makes your directory into a Git repository. Before running this, your directory is just a folder.

git help if you’re ever lost, type this. It brings up the most common git commands. You can also type git help SOME TERM to bring up specific help regarding SOME TERM. Note, replace SOME TERM with an actual git command like init or add.

git status this let’s you know what’s up. It will tell you what files have been modified and what files are untracked.

git add use this command to tell Git which new files to start monitoring. Bonus You run git add . to add all files that are changed or new.

git commit this commits our snapshot of changes to our Git repository.

git branch if you’re making a bunch of changes or expect your changes to take a long time, you might want to create an offshoot of the Git repository by making a new branch. This will be separate from the main branch and you can name it whatever you want git branch NAME.

git checkout this allows you to navigate between different branches, such as git checkout master or git checkout name

git merge this merges the changes you made in your separate branch with the main branch.

git push use this command to send your changes from your computer to Github.

git pull this is the opposite of push, it copies down the latest version of your repository from Github.

git clone PATH this copies an online repository from Github onto your local computer and into the path you list.

comments powered by Disqus