Wednesday, July 25, 2012

git basic

Normally, there is a classification of bare (empty) repository and non-bare repository. The bare repository is serving as a central media to connect any information to the other repositories. And there is always your working repository where you make change and improvment to your files inside.  Whenever you have made some change in your working repository, you should push it to the bare repository. And from your other computers other where or your account on cluster, you should 'git fectch' or 'git reset --hard' to the bare repository on your server.

Here is some basic procedures that one can build your repositories:
  • Making a local "non-bare" working repository, add a folder and files inside under git version control:
    1. We start from mkdir an empty folder
    2. mkdir wire
      cd wire
      git init
    3. And then copy the files to wire
    4. Add all the files inside folder 'wire', and git commit them all

    5. git add *
      git commit -a
      # Note, it is very important not to include .pyc, .py~ files otherwise your will get much unnecessary and unexpected trouble in the future
    6. Edit git comment to provide some information about the version and descripiton comment. And also you can add user name and email information about it:
      git config --global user.name "Voornaam Achternaam"
      git config --global user.email "aaa@bbb.com"
      git config --global core.editor "my favorate editor" #e.g. vim, nano, less
  • Make a bare repository, a remote copy of your local working reposiotry:
    1. making a remote bare repository using ssh to our server: ssh name@ssh.lorentz.leidenuniv.nl
      mkdir repo/wire.git
      cd repo/wire.git
      git init --bare
      exit
    2. Go back to your local working repository, and make remote add, and push your local repository to the remote bare repository wire.git at the server:

    3. git remote add origin name@ssh.lorentz.leidenuniv.nl:repo/wire.git
      git push origin master
    4. Note here "origin" is a name you can choose for the remote bare repository, you can name it for whatever you want, and you can check the all the remote repositories name or choose to delete them by using the command below
    5. git remote # check all the name of remote repository
      git remote rm aaa # remove the remote repository whose name is aaa
    6. After your git push from you local non-bare repository to the bare repository, you can go to your server and using "gitk --all" (if you have that) to check out the status, or using "git status". You can always use these command to check the status and branch.
  • Get a copy of a remote bare repository:
    1. If it is from your own computer or server account

    2. git clone /repo/wire.git
      git clone name:ssh.lorent.leidenuniv.nl:repo/wire.git
    3. If it is from other computer or server account

    4. git clone ~/otheruser/repo/hie_or_her_project.git
      git clone name:ssh.lorent.leidenuniv.nl:~otheruser/repo/his_or_her_project.git

      Note, unless you want to make some change in this repository (but usually people do not make change here), do not first make this folder 'git init'. Here you just copy or fetch it from a remote repository. You will always working and make file changes in you local non-bare working repository, i.e. wire here, and then push the changed files to ~repo/wire.git. You will always keep up changes from wire.git by using 'git fetch'. Make sure you understand this information flow direction once you made some change.
  • Keep up with changes from remote repositories:

    1. Once you make some change in your local non-bare working repository, you git push it to the bare repository, and to keep up the change at other places from this non-repository you need to:
    2. git fetch origin (or --all)
      git reset --hard origin
      Or you can delete the folder and make git clone, see above section
    3. In order to make sure you have the same version, you go to your copied repository and check

    4. git describe --always

      This will return a series number which identify the version of your repository, which is made after each time you made change in your working repository and git commit them. Each version has a unique version series number. So this number here should be coincides with the same number you using 'git describe --always' at your local non-bare working repository.

No comments:

Post a Comment