April 26

The versioning tool Git has long been on my list of things I want to look at me once. Right now I still use subversion . But while you can save with subversion changes only in a central repository that provides decentralized Git repositories that can be merged on demand from a central repository.

But before the first use is to install. Certainly, one can also translate Git from source, but both Linux [1] and for the Mac [2] are there any packages. The first steps in these two German tutorials [3] [4] explained. Is a detailed tutorial is German from Stanford University [5] .

Scenario


My scenario is as follows:

  • a central repository on my Mac mini (which I used as a server)
  • a distributed repository on my Mac mini (if I'm sitting times before)
  • a distributed repository on my Ubuntu laptop (with you)

It starts with the project that you want versioned with Git. The terminal is the developer's favorite friend and why the full functionality of Git is addressed only to them (is an Eclipse integration, it also [6] ). But one step at a time.

Step 1: versioning of existing project with Git


First you have to git his name and an email address be known. Git uses this information later in the release comments.

  config --global user.name "Gero Klinkmann" > Git config - global user.name "Gero Klinkmann"
 config --global user.email me @ example.com > Git config - global user.email me@example.com 

Then you can be first git repository with git init ersellen. For me it is on the Mac mini, to be built on the next step, the central repository.

  ~ / workspace / testGroovy > Cd ~ / workspace / test groovy
 init > Git init
 add . > Git add.
 commit > Git commit 

The commands speak for themselves. When commit can open the vi editor, so you can add a comment for the current state. The command syntax of the vi is not very intuitive, so by all who know them not, just add the necessary commands to the comment:

  • [I] change in the insert mode.
  • Leave a comment.
  • [Esc] switch to the command mode.
  • [: Wq] spoke and exit the vi.

Step 2: Create a centralized git repository


The newly created repository then the repository on the remote Mac. The clone of it is about the argument bare to the central repository on the Mac.

  ~ / git > Mkdir ~ git /
 ~ / workspace / testGroovy > Cd ~ / workspace / test groovy
 clone --bare .git ~ / git / testGroovy.git > Git clone - bare git ~ / git / testGroovy.git. 

Step 3: central Git repository clone


On the Linux laptop is supposed to create a distributed repository. Therefore it is necessary to clone the central repository on the Mac. Both computers are connected via ssh. Furthermore, when cloning the git-upload-pack (and that of the computer, where the central repository is - for me that is the Mac) is required.
To avoid problems, such as bash: git-upload-pack: command not found prevention should be the place (in my case it is / usr / local / git / bin / git-upload-pack) to specify the command to clone.

  ~ / projekte > Cd ~ projects /
 clone --upload-pack / usr / local / git / bin / git-upload-pack \ > Git clone - upload-pack bin / usr / local / git / / git-upload-pack \
    username @ server / full / remote / path / to / testGroovy.git testGroovy ssh: / / username @ servername / full / remote / path / to / test testGroovy.git groovy 

This one does not always pay attention to is this can also be deposited in the git configuration file.

  ~ / projekte / testGroovy > Cd ~ / projects / groovy test
 .git / config > Vi. Git / config
    ] [Remote "origin"]
         :refs / remotes / origin /* fetch = + refs / heads / *: refs / remotes / origin / *
         username @ server / full / remote / path / to / testGroovy.git url = ssh: / / username @ servername / full / remote / path / to / testGroovy.git
         usr / local / git / bin / git-upload-pack upload pack = / usr / local / git / bin / git-upload-pack
         usr / local / git / bin / git-receive-pack receivepack = / usr / local / git / bin / git-receive-pack 

Step 4: from local to central repository


Changes to the sources are first in the local repository git commit -a versioned. Also in this commit opens the vi editor for a version comment. With git push the changes to the local repositories are communicated to the central repository.

  ~ / projekte / testGroovy > Cd ~ / projects / groovy test
 commit -a > Git commit-a
 push > Git push 

Step 5: Local and central repository on a server


I had started with a local repository on my Mac. About git clone-bar, an additional central repository was created. But still there is no connection between the two. This is done through an entry in the configuration file of the local Git repositories.

  ~ / workspace / testGroovy > Cd ~ / workspace / test groovy
 .git / config > Vi. Git / config
    ...
    # Connect to the central repository
    ] [Remote "origin"]
         :refs / remotes / origin /* fetch = + refs / heads / *: refs / remotes / origin / *
         path / to / git / testGroovy.git url = / full / path / to / git / testGroovy.git
    ] [Branch "master"]
         remote = origin
         master merge = refs / heads / master 

Conclusion:
A little configuration is necessary even if you want to use to speak with both centralized and decentralized Git repositories. For this effort, but you get a very powerful, very stable and fast version control system that does not require a connection to a central repository.

Links:
[1] git-core - Core packages for Ubuntu
[2] git-osx-installer - Google Code Project
[3] German short git tutorial - on interaktionsdesigner.de
[4] German short git tutorial - on-line tutorials.net
[5] detailed German Git Tutorial - Stanford University
[6] EGit - Eclipse plugin for Git

gklinkmann written by \ \ tags: , , , ,

No Responses to "Tutorial - Getting Started with Git"

  1. google code - switching from svn to git 'all IT Says:

    [...] Tutorial - Getting Started with Git Bookmark [...]

Add a comment

Yes, I would like to be notified about comments!