41
GIT By Serhiy Yakovyn

Git

Embed Size (px)

Citation preview

Page 1: Git

GIT

BySerhiy Yakovyn

Page 2: Git

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

GIT to SVN mapping

Create the new repo:svnadmin create reposvn import file://repo

git initgit add .git commit

Page 4: Git

GIT to SVN mapping

To revert:svn revert pathGit checkout path

Page 5: Git

GIT to SVN mapping

To commit:svn commit

git commit -a

Page 6: Git

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

GIT to SVN mapping

List:svn list http://example.com/svn/branches/git branch

Page 8: Git

GIT to SVN mapping

Moving between revisions:svn update -r revsvn update

git checkout rev git checkout prevbranch

Page 9: Git

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

GIT to SVN mapping

Pick commit from another branch:svn merge -c rev urlgit cherry-pick rev

Page 11: Git

GIT to SVN mapping

Cloning remote repo:svn checkout url

git clone url

Page 12: Git

GIT to SVN mapping

Remote branch:svn switch urlgit checkout --track -b branch origin/branch

Page 13: Git

GIT to SVN mapping

Remote update:svn updategit pull

Page 14: Git

GIT to SVN mapping

Remote commit:svn commitgit push

Page 15: Git

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

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

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

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

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

Some commonly used workflows

1. Pull to update your local mastergit checkout mastergit pull origin master

Page 21: Git

Some commonly used workflows

2. Check out a branchgit checkout -b <branch>

Page 22: Git

Some commonly used workflows

3. Do work in your feature branch, committing early and oftenHacking…git commitHacking…git commitHacking…git commit

Page 23: Git

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

Some commonly used workflows

5. Interactive rebase (squash) your commitsgit rebase -i origin/master

Page 25: Git

Some commonly used workflows

6. Merge your changes with mastergit checkout mastergit pull git merge <branch>

Page 26: Git

Some commonly used workflows

7. Push your changes to the upstreamgit push origin master

Page 27: Git

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

GIT SVN

2. Hacking. Just usual GITgit checkout –b <branch>hacking…git commithacking…

Page 29: Git

GIT SVN

3. Updating from SVNgit svn rebaseorgit svn fetchgit svn rebase –l

Page 30: Git

GIT SVN

4. Preparing your workgit rebase –i remote/<branch>

Page 31: Git

GIT SVN

5. Committing back to SVNgit svn dcommit

Page 32: Git

GIT SVN

6. Branching:git svn branch

Page 33: Git

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

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

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

GIT internals

Tree object

Page 37: Git

GIT internals

Tree objectgit update-indexgit write-treegit read-tree

Page 38: Git

GIT internals

Commit Objectsgit commit-tree

Page 39: Git

GIT internals

Git Referencesgit update-ref

Page 40: Git

Questions?