GIT & github
SHARE YOUR CODE
![](https://s3.amazonaws.com/media-p.slid.es/uploads/rafaellaverde/images/179325/Git-Logo-1788C.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/rafaellaverde/images/179326/Octocat.png)
Why should I use version control?
Why should I use version control?
Have you ever:
- Made a change to code, realized it was a mistake and wanted to revert back?
- Lost code or had a backup that was too old?
- Had to maintain multiple versions of a product?
- Wanted to see the difference between two (or more) versions of your code?
- Wanted to prove that a particular change broke or fixed a piece of code?
Why should I use version control?
Have you ever:
- Wanted to review the history of some code?
- Wanted to submit a change to someone else's code?
- Wanted to share your code, or let other people work on your code?
- Wanted to see how much work is being done, and where, when and by whom?
- Wanted to experiment with a new feature without interfering with working code?
Why git?
- Speed
- Simple design
- Strong support for non-linear development (thousands of parallel branches)
- Fully distributed
- Able to handle large projects like the Linux kernel efficiently (speed and data size)
why github?
- It's widely in use
- Social networking functionality
- Pastebin-style site called Gist
- Is a community
- Octocat octodex.github.com
- github pages pages.github.com
![](https://s3.amazonaws.com/media-p.slid.es/uploads/rafaellaverde/images/179326/Octocat.png)
A social network for programmers :)
history of git
![](https://s3.amazonaws.com/media-p.slid.es/uploads/rafaellaverde/images/179615/220px-Linus_Torvalds.jpeg)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/rafaellaverde/images/179618/LinuxLogo.png)
Git basics
Snapshots, Not Differences
![](http://git-scm.com/figures/18333fig0104-tn.png)
![](http://git-scm.com/figures/18333fig0105-tn.png)
git basics
Nearly Every Operation Is Local
You have the entire history of the project right there on your local disk
Git Has Integrity
Everything in Git is check-summed
Git Generally Only Adds Data
it is very difficult to lose data
git basics
The Three States
Getting Started
config git
git config {key} {value}
user.name
user.email
core.editor
merge.tool
git config --list
Getting Started
Help
git help <verb>
git help config
Auto-Completion
https://github.com/git/git/blob/master/contrib/completion/git-completion.bashsource ~/.git-completion.bash
Setting Up a Git Repository
$ git init
$ git init --bare <directory>
![](https://gp1.wac.edgecastcdn.net/8029C4/wac-small/wac/landing/git/tutorial/git-basics/pageSections/00/contentFullWidth/0/tabs/0/pageSections/0/contentColumnTwo/0/imageBinary/git-tutorial-basics-init.png)
![](https://gp1.wac.edgecastcdn.net/8029C4/wac-small/wac/landing/git/tutorial/git-basics/pageSections/00/contentFullWidth/0/tabs/00/pageSections/01/contentFullWidth/00/imageBinary/git-tutorial-basics-init-barrepositories.png)
$ git clone git://github.com/schacon/simplegit-progit.git
![](https://gp1.wac.edgecastcdn.net/8029C4/wac-small/wac/landing/git/tutorial/git-basics/pageSections/00/contentFullWidth/0/tabs/0/pageSections/00/contentColumnTwo/0/imageBinary/git-tutorial-basics-clone.png)
Setting Up a Git Repository
svn vs git
Setting Up a Git Repository
$ git add *.py
$ git add README
![](https://gp1.wac.edgecastcdn.net/8029C4/wac-small/wac/landing/git/tutorial/git-basics/pageSections/00/contentFullWidth/0/tabs/0/pageSections/02/contentColumnTwo/0/imageBinary/git-tutorial-basics-add.png)
$ git commit -m 'initial project version'
![](https://gp1.wac.edgecastcdn.net/8029C4/wac-small/wac/landing/git/tutorial/git-basics/pageSections/00/contentFullWidth/0/tabs/0/pageSections/03/contentColumnTwo/0/imageBinary/git-tutorial-basics-commit.png)
Setting Up a Git Repository
Setting Up a Git Repository
inspecting a git repository
$ git status
$ git log
inspecting a Git Repository
inspecting a Git Repository
$ git blame <file>
![http://www.linuxhispano.net/tira/blame.png](http://www.linuxhispano.net/tira/blame.png)
other useful commands
$ cat .gitignore
$ git diff
$ git diff --staged
$ git rm <file>
$ git rm --cached <file>
$ git mv <file_from> <file_to>
Undoing Things
$ git commit --amend
$ git reset
$ git checkout <commit> <file>
$ git checkout <branch>
git revert <commit>
git clean
undoing things
reset vs revert
Don’t Reset Public History
Git Branches
![Git Tutorial: Branching and Merging](https://gp1.wac.edgecastcdn.net/8029C4/wac-small/wac/landing/git/tutorial/git-branches/pageSections/0/contentColumnTwo/0/imageBinary/git-tutorial_branching-merging.png)
git branches
$ git branch <branch>
![Git Tutorial: Create new branch](https://gp1.wac.edgecastcdn.net/8029C4/wac-small/wac/landing/git/tutorial/git-branches/pageSections/00/contentFullWidth/0/tabs/00/pageSections/02/contentFullWidth/02/imageBinary/git-tutorial_branching-1-exbranches2.png)
![Git Tutorial: git branch](https://gp1.wac.edgecastcdn.net/8029C4/wac-small/wac/landing/git/tutorial/git-branches/pageSections/00/contentFullWidth/0/tabs/00/pageSections/01/contentFullWidth/00/imageBinary/git-tutorial_branching-1.png)
git branches
$ git checkout <branch>
git branches
$ git merge
$ git merge --no-ff
fast-forward 3-way merge
fast-forward 3-way merge
![Git Tutorial: Three way merge](https://gp1.wac.edgecastcdn.net/8029C4/wac-small/wac/landing/git/tutorial/git-branches/pageSections/00/contentFullWidth/0/tabs/02/pageSections/01/contentFullWidth/02/imageBinary/git-tutorial_merge-three-way.png)
Resolving Conflicts
![http://www.linuxhispano.net/tira/conflictos.png](http://www.linuxhispano.net/tira/conflictos.png)
$ git merge some_branch Auto-merging index.html CONFLICT (content): Merge conflict in index.html Automatic merge failed; fix conflicts and then commit the result.
Working with Remotes
$ git remote
$ git remote add test http://dev.example.com/test.git
$ git fetch <remote> <branch>
$ git branch -r
$ git merge origin/master
git pull <remote> <branch>
git push <remote> <branch>
Git Work-flows
getting stated with github
https://help.github.com/articles/set-up-git
useful links and references
https://www.atlassian.com/git/tutorial
http://zrusin.blogspot.com/2007/09/git-cheat-sheet.html
http://www.vogella.com/articles/Git/article.html
http://marklodato.github.io/visual-git-guide/index-en.html
Gracias
git & github
By Rafael Laverde
git & github
- 2,171