git
TRANSCRIPT
![Page 1: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/1.jpg)
GIT
BySerhiy Yakovyn
![Page 2: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/2.jpg)
Agenda
• Describe how GIT commands corresponds to SubVersioN ones.
• Provide some commonly used workflows.• Explain how to use GIT when your team works
with SVN.• Give a quick overview of GIT internals
![Page 3: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/3.jpg)
GIT to SVN mapping
Create the new repo:svnadmin create reposvn import file://repo
git initgit add .git commit
![Page 4: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/4.jpg)
GIT to SVN mapping
To revert:svn revert pathGit checkout path
![Page 5: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/5.jpg)
GIT to SVN mapping
To commit:svn commit
git commit -a
![Page 6: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/6.jpg)
GIT to SVN mapping
Branching:svn copy http://example.com/svn/trunk http://example.com/svn/branches/branch svn switch http://example.com/svn/branches/branch
git branch branch git checkout branch
![Page 7: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/7.jpg)
GIT to SVN mapping
List:svn list http://example.com/svn/branches/git branch
![Page 8: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/8.jpg)
GIT to SVN mapping
Moving between revisions:svn update -r revsvn update
git checkout rev git checkout prevbranch
![Page 9: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/9.jpg)
GIT to SVN mapping
(assuming the branch was created in revision 20 and you are inside a working copy of trunk) svn merge -r 20:HEAD http://example.com/svn/branches/branch
git merge branch
![Page 10: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/10.jpg)
GIT to SVN mapping
Pick commit from another branch:svn merge -c rev urlgit cherry-pick rev
![Page 11: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/11.jpg)
GIT to SVN mapping
Cloning remote repo:svn checkout url
git clone url
![Page 12: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/12.jpg)
GIT to SVN mapping
Remote branch:svn switch urlgit checkout --track -b branch origin/branch
![Page 13: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/13.jpg)
GIT to SVN mapping
Remote update:svn updategit pull
![Page 14: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/14.jpg)
GIT to SVN mapping
Remote commit:svn commitgit push
![Page 15: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/15.jpg)
Some commonly used workflows
1. Write new features in feature branches.2. Integrate on the master branch.3. Deploy from the release branch.
![Page 16: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/16.jpg)
Some commonly used workflows
1. Write new features in feature branches.# create a new feature branch in the remote repo named feature_branch git push origin master:refs/heads/feature_branch
# make sure we've got everything updated from the remote repo git fetch origin
# create a local branch named feature_branch that tracks # the remote feature_branch git branch --track feature_branch origin/feature_branch
# check out the new branch git checkout feature_branch
![Page 17: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/17.jpg)
Some commonly used workflows
2. Integrate on master branch.git merge master
git checkout master git merge feature_branch
# this has to be in competition for one of the least intuitive # commands ever, but it removes the remote branch git push origin :refs/heads/feature_branch
# remove the local branch git branch -d feature_branch
![Page 18: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/18.jpg)
Some commonly used workflows3. Deploy from the release branch.# checkout the deploy branch git checkout deploy
# pull the deploy branch, just to be sure everything's up to date git pull origin deploy
# merge the master branch into the deploy branch git merge master
# tag the release that we're about to make git tag -a -m "My comments about this release" [tag_name]
# push it all up to the remote repository git push --tags origin deploy
# switch back to the master branch, # since we never do any work on the deploy branch git checkout master
![Page 19: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/19.jpg)
Some commonly used workflows
1. Pull to update your local master2. Check out a feature branch3. Do work in your feature branch, committing early and often4. Rebase frequently to incorporate upstream changes5. Interactive rebase (squash) your commits6. Merge your changes with master7. Push your changes to the upstream
![Page 20: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/20.jpg)
Some commonly used workflows
1. Pull to update your local mastergit checkout mastergit pull origin master
![Page 21: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/21.jpg)
Some commonly used workflows
2. Check out a branchgit checkout -b <branch>
![Page 22: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/22.jpg)
Some commonly used workflows
3. Do work in your feature branch, committing early and oftenHacking…git commitHacking…git commitHacking…git commit
![Page 23: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/23.jpg)
Some commonly used workflows
4. Rebase frequently to incorporate upstream changesgit fetch origin master git rebase origin/masterOr (longer way):git checkout master git pull git checkout <branch> git rebase master
![Page 24: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/24.jpg)
Some commonly used workflows
5. Interactive rebase (squash) your commitsgit rebase -i origin/master
![Page 25: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/25.jpg)
Some commonly used workflows
6. Merge your changes with mastergit checkout mastergit pull git merge <branch>
![Page 26: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/26.jpg)
Some commonly used workflows
7. Push your changes to the upstreamgit push origin master
![Page 27: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/27.jpg)
GIT SVN
How to use GIT when your team works with SVN?1. Creating working copy? – no! working repo.git svn init …Some magic git svn fetchOr (if you are lucky! – I’ve never been):git svn clone …
![Page 28: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/28.jpg)
GIT SVN
2. Hacking. Just usual GITgit checkout –b <branch>hacking…git commithacking…
![Page 29: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/29.jpg)
GIT SVN
3. Updating from SVNgit svn rebaseorgit svn fetchgit svn rebase –l
![Page 30: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/30.jpg)
GIT SVN
4. Preparing your workgit rebase –i remote/<branch>
![Page 31: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/31.jpg)
GIT SVN
5. Committing back to SVNgit svn dcommit
![Page 32: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/32.jpg)
GIT SVN
6. Branching:git svn branch
![Page 33: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/33.jpg)
GIT internals
.git contentHEAD – the checked out branchconfig – configuration options description – description (used by GitWeb)hooks/ index - staginginfo/ objects/ - contentrefs/ - pointers to commit objects in branches
![Page 34: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/34.jpg)
GIT internals
Git is a content-addressable filesystem.This means that at the core of Git is a simple key-value data store. You can insert any kind of content into it, and it will give you back a key that you can use to retrieve the content again at any time. git hash-object – stores the file in GIT
![Page 35: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/35.jpg)
GIT internals
git cat-file - provides content or type and size information for repository objects
BLOB – basic object type. Every file is stored in it
![Page 36: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/36.jpg)
GIT internals
Tree object
![Page 37: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/37.jpg)
GIT internals
Tree objectgit update-indexgit write-treegit read-tree
![Page 38: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/38.jpg)
GIT internals
Commit Objectsgit commit-tree
![Page 39: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/39.jpg)
GIT internals
Git Referencesgit update-ref
![Page 40: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/40.jpg)
Questions?
![Page 41: Git](https://reader033.vdocuments.site/reader033/viewer/2022060109/5551992eb4c905013a8b4ae1/html5/thumbnails/41.jpg)
Useful links
http://progit.org/book/Git Workflow – GitHubGit SVN Workflowhttp://maymay.net/blog/2009/02/24/how-to-use-git-svn-as-the-only-subversion-client-youll-need/and many-many-many others…