Intro to
a version control system
What is 'Git'?
Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
Git is easy to learn and has a tiny footprint with lightning fast performance. It outclasses SCM tools like Subversion, CVS, Perforce, and ClearCase with features like cheap local branching, ..., and multiple workflows.
a snippet taken from git-scm.com
So, What does that mean?
To help understand why GIT is so helpful to developers we need to travel back in time!
Old ways of saving your work
- Copying the entire folder
e.g. project_backup1
- Copying a folder? PSSH YOLO SON
No history of changes
, project_backup2
Ways to collaborate
- Emailing an entire project
- What happens when you both make changes to the same file?
- Why did 'FozzieBear' make this change to perfectly working code?
"What if I want to experiment?"
You can but...
? ? ?
Who created GIT?
Linus Torvalds
- Creator of the Linux Kernal
- Open-Source Evangelist
- Jerk
“I’m an egotistical bastard, so I name all my projects after myself. First Linux, now Git”.
British slang for rotten person.
git init
Starting the party
In a working directory...
initiates GIT into the current directory...
which is now known as your
"working directory"
Git has three "trees" it works with:
- Working Directory
- Index
- Head
Working Directory is all of the actual files you are working with.
Index
Which is the staging area for your changes before you save them
HEAD
Which points to the last commit you made
git status
back to setting up our new repo...
Next Step after initiating a GIT repository
is to stage files to be committed.
git add [path/to/file/here]
git add index.html
git add public/javascripts/main.js
git add public/
git commit -m 'initial commit'
-m stands for message. Why is having a message useful?
Great, things are committed... to where? Locally!
Can you have remote storage? Yes!
Working with branches
Branches allow us to work with our code in a safe, sandboxed-way.
Instead of that
We 'GIT'
Working Directory
.git
Branches
Images those branches as a Folder but without the mess.
git checkout -b add-database
git checkout -b create-tweet-system
All these branches are tracked by git and live in your .git folder
git checkout add-database
git checkout create-tweet-system
Merging
The process of putting together work from different branches.
[work finished and commited to the branch named 'fix-login-bug']
$ git status
On Branch 'fix-login-bug'
nothing to commit, working directory clean
$ git checkout master
# git merge [branch name]
$ git merge fix-login-bug
Pushing your changes to a Remote Repository
firstly, a remote must be set
git remote add [local-name] [url]
git remote add origin git@github.com/sgnl/magical_project.git
Once set you can push to it by it's name
git push origin [branch name]
git push origin master
You can have multiple remotes to push updates to and pull new code from.
Remotes
- Fork creates your own copy of a project to work with, not linked to the repo you forked off of.
- Clone creates the repo that is linked to the repo you clones
- Push new changes to remote
- Pull new changes from remote into your local
$ git checkout -b 'build-shopping-cart'
$ git checkout -b 'user-session'
$ git commit -m 'add user session; project uses session_magic.js'
$ git checkout -b 'product-item-cart'
$ git commit -m 'add ability for user to interact with shopping
cart through user session'
$ git checkout build-shopping-cart
$ git checkout build-shopping-cart
$ git merge user-session
$ git merge 'product-item-cart'
FozzieBear's work flow
$ git checkout master
$ git merge build-shopping-cart
# push changes to remote repo
$ git push origin master
FozzieBear's work flow (cont.)
Now Ray is able to get FozzieBear's changes
# check what branch you are on
$ git status
# git fetch [remote] [branch name]
$ git fetch origin master
$ git log
Ray can see a log of commits done to the project
Meet GIT
By Ray Farias
Meet GIT
- 1,233