Git

From YobiWiki

Jump to: navigation, search

Contents

Links

Install

sudo apt-get install git-svn git-doc git-gui tig

Writing to global ~/.gitconfig file:

git config --global user.name "Your Name Comes Here"
git config --global user.email you@yourdomain.example.com
git config --global color.diff auto
git config --global color.status auto
git config --global color.branch auto

Creating a .git in the current (project) directory:

git init

Working on a project

Initial project

Add manually files/directories e.g. with

git init
git add .
git commit

Copying existing project

Clone an existing Git repository into a to-be-created target directory:

git clone /path/to/other/repository target

Remote repositories can also be accessed with paths like

ssh://login@host/path/to/repository
git://git.software.org/trunk
http://git.software.org/trunk

Later to update the local repository according to the remote repository:

git pull

Symmetrically the remote repository owner could also get the changes we've done locally if she does:

git pull /path/to/our/target

Or we could send them ourselves if we've write access on the remote:

git push

BTW the remote can create a shortcut to us to not have to provide our full path everytime

git remote add ourshortcut /path/to/our/target

And now use directly

git remote show ourshortcut
git pull ourshortcut

Note that git pull ourshortcut ==

git fetch ourshortcut
git merge ourshortcut/master

Using a Subversion server

Using git-svn:

Getting the full project:

# git clone =>
git-svn --username=xxxxx clone http://subversion.server.com/project -T trunk -b branches -t tags
(git-gc to compress if it took a big room)

Updating the local repository according to the subversion server:

# git pull =>
git-svn rebase

Some tips from here:

  • While doing a rebase, if anything bad happens, you end up on a "(no-branch)" branch.
  • When doing a "git status", you'll see a ".dotest" file in your working directory. Just ignore it.
  • If you want to bail, do a "git rebase --abort". (Note there is no "git svn rebase --abort".)
  • Fix the merge conflict file manually, then do a "git add [file]".
  • Next do a "git rebase --continue". (Note there's no "svn" version of this either.)
  • If it complains about "did you forget to call 'git add'?", then evidently your edit turned the conflict into a no-op change. Do a "git rebase --skip" to skip it. (Very weird, but true.)
  • Rinse and repeat until the lather is gone, your scalp silky smooth, and the rebase is complete. At any time you can "git rebase --abort" to bail.

Sending the local changes to the subversion server:

# git push =>
git-svn dcommit


By error I did

git commit --amend

on a synchronized git repository, so I lost remotes/trunk in the gitk view but the remote branch is still visible with git branch -r, strange...

$ git-svn rebase
First, rewinding head to replay your work on top of it...
Nothing to do.

solved the problem

SVN relocation:
git-svn doesn't support relocation of the SVN server and doing it by hand is very difficult so if possible push all your local changes before relocation then make a new clone from the new location.

One day you'll be bored of SVN and want to get rid of it completely :-)

Create a new git repository remotely somewhere else (see above), which will become the origin we didn't have.

git remote add origin ssh://myuser@repo.or.cz/srv/git/myproject.git
git pull origin master
git push

Now it's better to make sure git-svn cannot interfere with it anymore:
Fetch the project in a new place

git clone ssh://myuser@repo.or.cz/srv/git/myproject.git
git pull

And drop your old git-svn working directory

Using repo.or.cz

http://repo.or.cz/ can be used to make a publicly available git repo.

  1. Create a new user: http://repo.or.cz/m/reguser.cgi
    When creating a user you need a public ssh key to authenticate yourself.
  2. Create a new repo: http://repo.or.cz/m/regproj.cgi
    • two different modes are available for a new repo:
      • mirror mode: the new repo will mirror an existing repo by checking it every hour for changes
      • push mode: users you give permission to can push to the repo
    • all the info asked when you register your repo can be changed afterwards on the project admin page
  3. Add yourself and other users you want to give "push" access via the admin page
  4. Git repo is accessible via
    • git://repo.or.cz/<project name>.git
    • http://repo.or.cz/r/<project name>.git
    • git+ssh://<user>@repo.or.cz/srv/git/<project name>.git (for push)

Basic usage

Edition

Schedule a file for committing

git add 
Gears LocalServer