Sunday, September 30, 2012

git (using gitosis)

gitosis is a great way to have a private git server. To install gitosis and perform the basic configurations refer to this guide. gitosis can use ssh access to your remote repositories. Unlike svn (and many other version control systems), git keeps an entire snapshot for your commits instead of a series of diffs. This is great because you can see the entire history of your project locally and develop locally. This comes handy when you do not have access to the internet to push your commits to the remote repository. Moreover, even in the event that the remote repository dies, you can still recover your code using your local database. For this and many other reasons (such as the distributed mirroring and the free github), git is the most popular choice for version control.


Installing gitosis in your remote server

Once you have installed gitosis in your remote server, you must clone gitosis-admin repository to your local machine. You can perform numerous administrative tasks locally via this repository such as adding new projects.

The first time you use git to push something you must specify your name and e-mail address. This can be done as follows.

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

To add a new repository do as explained here.

  1. cd gitosis-admin
  2. git pull   This will update your gitosis-admin repository
  3. If you do not have your gitosis-admin repository, then you must first clone it by
    git clone gitosis@server:gitosis-admin.git
  4. Now edit the gitosis.conf file and add your newproject details
    [group helloproject]
    members = mylogin@myhost
    writable = helloproject
    Note that the last one is "writable" and not "writeable"
  5. Now commit the changes you made to gitosis-admin repository by,
    git commit -am "added the project helloproject"
    next push the commit to the local db by git push
  6. Now move to the directory that contains files for your new project "helloproject". Then do git init
  7. This will initialize the new repository. You can add individual files to track using
    git add filename
    You cannot add an empty directory to git repository. When you add a file from a directory that directory will be automatically added to the repository. However, if you want to add an empty directory to the repository you can either place a dummy README file in that directory or write a .gitignore file in the directory that you want to add. The .gitignore directory must contain the following two lines.
    # Add everything in this direcory
    *
    # Except for this file.
    !.gitignore
  8. Once you have added the files for the newly created helloproject you must commit them.
    git commit -am "Initial commit for helloproject"
  9. Now you need to add this new project to your remote repository by
    git remote add origin ssh://gitosis@myserver/helloproject.git
  10. You can now push the changes to your remote repository
    git push --all
  11. In order to be able to pull back to the same directory (without cloning the pushed project from the remote server) you must edit .git/config file as follows.
    [branch "master"]
    remote = origin
    merge = refs/heads/master
  12. That is it.
Git development cycle (command used frequently)
  1. You would either add an existing project to git as explained above or will clone a project from the remote repository. To clone do as follows.
    git clone gitosis@myserver:helloproject.git
  2. Now you will modify some tracked files and/or add new files to be tracked using
    git add filename
  3. Note that there is this concept of staging in git which means you must first "stage" files to be committed and then perform the actual committing. This means you will have to add again any files that you have modified in order for them to get committed. This additional staging step can be skipped by using the -a option during commit.
    git commit -am "message"
  4. Commit actually commit things to your local repository. It does not push your changes to your remote server. To push your changes to the server do as follows.
    git push
  5. This is the basic (frequent) development cycle. Note that if someone else have pushed before you (i.e. origin has been modified by some other person other than you), then git push will fail. You must first git pull their changes and then check them with your modifications (git fetch will not merge but git pull will try to merge) and then git push again.
Git useful tricks
  1. Use git status to see what are the changes that are going to be committed in the next commit.
  2. You can use tags to easily refer (and checkout) important milestones of your project.
    To list the current tags do
    git tag -l
  3. To create a new tag do as follows
    git tag -a v1.0 -m "first version"
  4. To push your tags to the remote server do,
    git push origin v1.0
  5. Now when someone clones this repository that person will also receive the tag v1.0. After cloning a project you can checkout a specific tag as follows.
    git checkout v1.0
  6. If we want to delete the tag see here.
Git hub
  • cloning a repository from github
    • git clone git://github.com/Bollegala/svdmi.git
  • You might not be able to push to the original git directory if you have not set the git url as follows
    • git remote set-url origin git@github.com:Bollegala/svdmi.git 
 


Saturday, September 29, 2012

fish shell vs. bash

fish shell is a great tool. But it can be confusing in the initial stages especially to adapt from bash to fish shell. Some important differences are highlighted below.


  1. escaping wildcards such as *
    use double quotes
    rm "*.pyc"
  2. command expansion using backticks
    the bash command
    rm `find -type d -name .svn` would be
    rm (find -type d -name .svn) in fish shell

Continuously monitor GPU usage

 For nvidia GPUs do the follwing: nvidia-smi -l 1