Kyle Rogers & Nate Mara
2014-10-22
Git is a free and open source version control tool.
In 2002, the Linux source code began to be managed by BitKeeper (proprietary software).
BitKeeper revoked license for Linux in 2005.
I'm an egotistical bastard, and I name all my projects after myself. First Linux, now git.
-- Linus Torvalds
Linus developed Git during a two week coding session. After two months, version 1.0 was released.
Since 2005, has developed into one of the largest source code management tools.
A data structure, that contains, among other things a historical record of changes in the repository.
A snapshot of your repository at a specific time.
Set of commits, generally used for a single purpose. Branches can be combined with git merge
git init
Create a new, empty repository in the current directory
git add <file>
Add <file>
to the staging area. Files in the staging area will be added to the next commit.
git commit -m '<message>'
Commit files in the staging area. <message>
should be a message that explains the changes made in the commit.
git help <command>
Get help for the given command
git checkout <branch>
Switch to the branch identified by <branch>
. To create a new branch with this command, add the -b
flag.
git checkout <file>
When a file on disk differs from the version stored in Git, use this to revert <file>
to the state stored in Git.
git status
Before we do any work with Git, we have to set some settings:
git config --global user.name "My Name"
git config --global user.email email@email.com
git config --global core.editor SOME_EDITOR
git config --global push.default simple
Let's create an empty Git repository at ~/git-repo/
mkdir ~/git-repo
cd ~/git-repo
git init
Let's add a readme file to our Git repo:
YOUR_EDITOR README.md
git add README.md
git commit -m 'add readme file'
Let's take a minute to look at what we just did:
On the next slides, we will look at each step more in depth with the git status
command:
$ vi README.md
$ git status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
README.md
nothing added to commit but untracked files present (use "git add" to track)
$ git add README.md
$ git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: README.md
$ git commit -m 'add readme file'
$ git status
On branch master
nothing to commit, working directory clean
$ git log
commit c9fd3e8dc41e0649fc3ba0e88bcc2f41a97d8144
Author: rogerskw <rogerskw@miamioh.edu>
Date: Wed Oct 22 15:00:53 2014 -0400
asdf
If you have many commits, the less command will be used.
A remote is a copy of the repo in another location such as a server (like GitHub)
Save commits to a remote repository using
$ git push origin master
Where 'origin' is the remote's name and 'master' is the current branch's name
What many beginner git repos look like:
Taking full advantage of git branching
Create a new branch with
$ git branch newbranchname
Switch to the branch with
$ git checkout newbranchname
Make some changes and commit them
After committing, switch back to the 'master' branch
$ git checkout master
Look for your changes
Merge your changes into the main development line
$ git merge newbranchname
Now you should see your changes from your branch
Large projects will have many branches
You can use git stash in order to save changes to a branch
without actually committing
This can be useful if you made changes that aren't working,
but need to go to another branch to do something else
Tag commits in order to give them an easier ID
Makes it easier to revert back to or identify releases
Shows who exactly committed each line of code
Useful for identifying who introduced a bug
Also useful for determining how much each person actually contributed
Can be used to reset the repo to a previous commit
Do a binary search on commits in order to determine when a bug was introduced