Git for Subversion Users Cheatsheet
Git for Subversion Users Cheatsheet
presented by
TOWER — the best Git client for Mac and Windows
SUBVERSION GIT
$ svnadmin create /path/to/repo $ git status
$ svn import /path/to/local/project http:// $ git diff
example.com/svn/ trunk -m "Initial import"
In case you’ve created new files or deleted old ones, you should
GIT
$ git init tell Git with the git add and git rm commands. You’ll be pleased to
$ git add . hear that it’s safe to inform Git after deleting or moving a file or
$ git commit -m "Initial commit"
even a folder. This means you should feel free to delete or move
even complete directory structures in your favorite editor, IDE,
or file browser and later confirm the action with the add and rm|
Cloning a Remote Repository commands.
Getting a copy of the project from a remote server seems almost SUBVERSION
$ svn add <file>
identical. However, after performing git clone, you have a full-
$ svn rm <file>
blown local repository on your machine, not just a working copy.
GIT
$ git add <file>
SUBVERSION $ git rm <file>
$ svn checkout
svn+ssh://[email protected]/svn/trunk
In its simplest form, committing can feel just like in Subversion.
GIT With the -a option, you tell Git to simply add all current local
$ git clone
changes to the commit.
ssh://[email protected]/path/to/git-repo.git
SUBVERSION
$ svn commit -m "message"
SUBVERSION You can add selected files to the staging area and even limit this to
$ svn log | less
certain parts (or even lines) of a file by specifying the -p option. This
GIT allows you to craft your commits in a very granular way and only
$ git log add changes that belong to the same topic in a single commit.
GIT
$ git add <file1> <file2>
$ git add -p <file3>
Branching & Tagging Everything else is taken care of for you: you can merge two
branches as often as you like, don’t have to specify any revisions
In contrast to Subversion, Git doesn’t use directories to manage and can expect the operation to be blazingly fast if you’re merging
branches. Instead, it uses a more powerful and lightweight approach. two local branches.
As you might have already noticed, the git status command also
If a merge conflict should occur, Git will already update the rest
informs you about which branch you are currently working on. And
of the working copy to the new state. After resolving a conflicted
in Git, you are always working on a branch!
file, you can mark it using the git add command.
SVN
$ svn copy http://example.com/svn/trunk/ SUBVERSION
$ svn resolved <file>
http://example.com/svn/branches/<new-branch>
GIT GIT
$ git add <file>
$ git branch <new-branch>
GIT If you only want to download & inspect remote changes (before
$ git checkout <branch>
integrating them), you can use git fetch. Later, you can integrate
the downloaded changes via git merge.
Listing all available local branches just requires the git branch|
command without further arguments. GIT
$ git fetch
SVN
$ svn list http://example.com/svn/branches/
In Subversion, data is automatically uploaded to the central server
GIT when committing it. In Git, however, this is a separate step. This
$ git branch
means you can decide for yourself if and when you want to share
your work. Once you’re ready, the git push command will upload
Creating tags is just as quick & cheap as creating branches. the changes from your currently active branch to the remote
branch you specify.
SVN
$ svn copy http://example.com/svn/trunk/
http://example.com/svn/tags/<tag-name> GIT
$ git push <remote> <branch>
GIT
$ git tag -a <tag-name>
Your teammates, too, will publish their work like this on a remote
(with the git push command). If you want to start working on such
a branch, you need to create your own local copy of it. You can
Merging Changes use the git checkout command with the --track option to do just
that: create a local version of the specified remote branch. You can
Like in newer versions of SVN, you only need to provide the branch later share the additional commits you’ve made at any time with
you want to integrate to the git merge command. the git push command, again.
SUBVERSION SUBVERSION
$ svn merge -r REV1:REV2 $ svn switch
http://example.com/svn/branches/<other-branch> http://example.com/svn/branches/<branch>
$ svn merge (or in newer SVN versions)
http://example.com/svn/branches/<other-branch> GIT
$ git checkout --track <remote>/<branch>
GIT
$ git merge <other-branch>