Thursday, November 25, 2010

GIT usage (for an SVN user)

I put together some stuff about git I found interesting.

Installation


To get started with git on Windows, you'll probably want to download TortoiseGIT (and this requires msysgit)


Setup


To use git, a username and email need to be configured. This can be done in of TortoiseSVN -> Settings -> Git -> Config.


Migration from SVN


A very good manual to migrate your existing SVN repository to GIT can be found in this blog post of Jon Maddox.

Good to know


Git tracks content not files
Many revision control systems provide an 'add' command that tells the system to start tracking changes to a new file. Git's 'add' command does something simpler and more powerful: git add is used both for new and newly modified files, and in both cases it takes a snapshot of the given files and stages that content in the index, ready for inclusion in the next commit.


Most SCM systems use Delta Storage systems - they store the differences between one commit and the next. Git does not do this - it stores a snapshot of what all the files in your project look like in this tree structure each time you commit. This is a very important concept to understand when using Git.


There is only one Git Directory per project (as opposed to one per subdirectory like with SVN or CVS), and that directory is (by default, though not necessarily) '.git' in the root of your project.


Git is much faster than SVN.


In SVN, each file & folder can come from a different revision or branch. At first, it sounds nice to have this freedom. But what this actually means is that there is a million different ways for your local checkout to be completely screwed up.


You have to tell SVN whenever you move or delete something. Git will just figure it out.


Branches are cheap and easy to merge, so this is a good way to try something out.


A single git repository can maintain multiple branches of development. The 'master' branch is a default branch that was created for you automatically. The 'git checkout branchname' command will switch between branches. The command 'git merge branchname' will merge changes from another branch in the current active branch.


The 'pull' command performs two operations: it fetches changes from a remote branch, then merges them into the current branch.


'git commit' commits locally, whereas 'git push origin master' pushes the master branch to the remote named 'origin').


Git adds complexity. Two modes of creating repositories, checkout vs. clone, commit vs. push... You have to know which commands work locally and which work with "the server" (I'm assuming most people still like a central "master-repository").


Git is MUCH better suited if some developers are not always connected to the master repository.


Even if you don't have commit rights for a project, you can still have your own repository online, and publish 'push requests' for your patches. Everybody who likes your patches can pull them into their project, including the official maintainers.


Drawbacks of Git:


  • it's much harder to learn, because Git has more concepts and more commands.
    • many Git commands are cryptic, and error messages are very user-unfriendly
  • revisions don't have version numbers like in subversion
  • you have to have a full copy of the repository, you can't work on partials


Git branching model


A very good post on git branching model
Pdf model overview
  • Central repo with 'origin/master' and 'origin/development' branches (infinte lifetime)
    • 'origin/master' branch reflects the production release
  • Supporting branches
    • feature branch: branches from development and merges into development, branch name different from master, develop, release-* or hotfix-*, exist in developers repos only, not in central origin
    • release branch: branches from development and merges into development and master, branch name release-*, all feature branches must be merged in development before release branch is branched off
    • hotfix branch: branches from development and merges into development, master and release, branch name hotfix-*


Central Repo


If you like to setup a git central repository on Windows (for example to replace your VisualSVN environment), you can follow this manual.

Update 23/04/2015: A good tutorial and Git related info can be found on this Atlassian site.

1 comment:

  1. some other branching strategies: https://medium.com/@patrickporto/4-branching-workflows-for-git-30d0aaee7bf

    ReplyDelete