Git a Stupid Introduction
-
Upload
raf-magana -
Category
Documents
-
view
240 -
download
0
Transcript of Git a Stupid Introduction
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 1/108
Git
A stupid Introduction to animbecile version control system
Rafael Magaña => [email protected]
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 2/108
Cheap branching, cheap tagging and easy merging
Git is an open source, distributed version control
system designed for speed and efficiency.
What else Git is?
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 3/108
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 4/108
git initmiércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 5/108
creates an empty git repository or reinitialize an existWhat does creating a repo exactly mean?
to create a directory named .git with some subdire
to create a file named HEAD that references the hemaster branch
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 6/108
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 7/108
git clone <repository> [<directory>
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 8/108
clones a repository into a newly created directory
creates remote-tracking branches for each branch incloned repo
checks out an initial branch equal to the cloned reposcurrently active branch.
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 9/108
git clone support different protocolsrsync://host.xz/path/to/repo.git/
[:port]/path/to/repo.git/
git://host.xz[:port]/path/to/repo.git/ ssh://[user@]host.xz[:port]/path/to/repo.git/
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 10/108miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 11/108
git configmiércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 12/108
gets and sets repository or global options
$ git config --global user.name “Rafael Magaña” ( ~/gitconfig)
$ git config --global user.email “[email protected]” (~/gitcon
$ git config user.name “Rafael Magaña” (.git/config)
$ git config user.email “[email protected]” (.git/config)
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 13/108miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 14/108
The git directory
.git directory that stores all history and meta informa
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 15/108
remote
a remote repository
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 16/108
local repository
the result of clone a remote with git clone <repo>
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 17/108
commit
to send your changes to your local repository
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 18/108
master branchthe first and default branch in a repo
(mostly used as dev branch)
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 19/108
origin
the default and first remote (upstream repository
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 20/108
origin/master
the remote branch called master in the remote called origin
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 21/108
working directory
the directory that holds the files you are working o
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 22/108
staging area
it’s where your changes must be placed before commit
it’s a place between your working directory and your local reposito
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 23/108
index
an alias for the staging area
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 24/108miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 25/108
Object
consist of three things:
type
size
content (be aware that git doesn’t care about files but content)
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 26/108
Type
blob, tree, commit and tag
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 27/108
Content
depends on the object
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 28/108
blob
it is used to store file data. it is generally a fi
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 29/108
tree
it is like a directory.
It references a bunch of other trees and/or blo
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 30/108
commit
points to a single object, marking it as what t
project looked like at a certain point in time
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 31/108
tag
a way to mark a specific commit
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 32/108
SHA1
All the information needed to represent the hisa project is stored in files referenced by a 40
"object name" that looks something like t
fdb25ef2c3baf28cb963e26c8949c632ff64b
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 33/108
git show fdb25e
SHA1
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 34/108
You can see that we have createda tree object for each directory(including the root) and a blob
object for each file. Then we havea commit object to point to theroot, so we can track what ourproject looked like when it wascommitted.
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 35/108
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 36/108
COMMIT_EDITMSG
the commit message holder file
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 37/108
COMMIT_EDITMSGif you issue “git commit”, git will open an edit
to edit the message, it will be stored in thisholder and then git will execute:
$git commit -m COMMIT_EDITMSG
once the editor is closed
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 38/108
HEAD
pointer to the current commit
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 39/108
ORIG_HEAD
previous state of HEAD
used to revert dangerous operations
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 40/108
config
your configuration preferences
(name, email, remotes, etc)
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 41/108
hooks/
pre/post action hooks (scripts)
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 42/108
index
it links the history to the current
contents of the working tree
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 43/108
logs/
a history of where your
branches have been
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 44/108
objects/
(commits, trees, blobs, tags)
the history
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 45/108
refs/
directory which stores pointers to local
and remote branches
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 46/108
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 47/108
Edit your files
Stage the changes
git add [-u]
Review your changes
git status
git diff
Commit the changes
git commit
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 48/108
git add/git add -u
git commit
git commit -a (executes git add -u)
git diff (comparision)
git diff --cached
git diff HEAD
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 49/108
editing files
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 50/108
without modified files
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 51/108
with modified files (in working directory)
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 52/108
staging the changes
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 53/108
git add README
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 54/108
git status
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 55/108
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 56/108
git reset HEAD README
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 57/108
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 58/108
git add README
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 59/108
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 60/108
reviewing changes
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 61/108
git diff (not staged changes)
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 62/108
git diff --cached (staged changes)
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 63/108
git diff HEAD (all the changes)
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 64/108
commiting changes
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 65/108
git commit
1e7059emiércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 66/108
git log
1e7059emiércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 67/108
fixing and editing commits
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 68/108
git show 1e7059e
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 69/108
Edit the README file
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 70/108
git add README
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 71/108
git commit --amend
miércoles 20 de octubre de 2010
it ill it/COMMIT MSG
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 72/108
git will open .git/COMMIT_MSG
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 73/108
save it and close the editor
git will commit for you
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 74/108
7572e98miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 75/108
git log
7572e98miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 76/108
git add/git add -u
git commit (amend)
git commit -a (executes git add -u)
git reset --soft
git reset --mixed
git push
git pull (git fetch and git merge or git rebase)
git reset HEAD
reset --hard
git fetch
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 77/108
git init (initializes a git repository)
git clone (brings remote repositories)
git config (configures preferences)
git status (shows the working tree status)
git add (takes changes to the index)
git diff (show changes in diff format)
git commit (takes changes to the local repo)
git log (shows the history)
git show (shows objects)
git reset (reset currenthe specified state)
git fetch (fetches obje
git merge (join two odevelopment historie
git pull = git fetch + g
one stepgit push (takes local the remote repository
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 78/108
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 79/108
git branch bugfixcreates a local branch
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 80/108
git checkout bugfixswitches to bugfix branch
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 81/108
git checkout -b bugfixcreates branch and switches to it
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 82/108
git checkout -b bugfixcreates branch and switches to it
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 83/108
git checkout -b dev -t origin/de
creates a local branch which tracks a remote bra
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 84/108
git branch -d bugfixdeletes bugfix branch
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 85/108
git branch -lshows local branches
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 86/108
git branch -rshows remote branches
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 87/108
git branch
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 88/108
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 89/108
John: git pull
git checkout -b task
git commit -am “C2”
git commit -am “C3”
git commit -am “C4”git commit -am “C5”
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 90/108
Peter: git pull
git checkout -b try_out
git commit -am “C6”
git commit -am “C7”
git commit -am “C8”
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 91/108
Sam: git pull
git checkout -b fixing
git commit -am “C9”
git commit -am “C10”
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 92/108
miércoles 20 de octubre de 2010
John, Peter and Sam are They need to “git pull”
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 93/108
Scott: git pullgit checkout master
git commit -am “C11”
git push origin master
y g p
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 94/108
git checkout master
Switching to our local master branch
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 95/108
git pull origin master
Updating our local respository
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 96/108
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 97/108
miércoles 20 de octubre de 2010
git checkout mas
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 98/108
git merge try_out
git push origin ma
git branch -d try_o
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 99/108
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 100/108
miércoles 20 de octubre de 2010
git checkout try_o
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 101/108
git rebase master
git rebase try_out
git push origin ma
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 102/108
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 103/108
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 104/108
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 105/108
git tag v2.0
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 106/108
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 107/108
Rafael Magaña => [email protected]
miércoles 20 de octubre de 2010
8/8/2019 Git a Stupid Introduction
http://slidepdf.com/reader/full/git-a-stupid-introduction 108/108