Resources‎ > ‎Standard Procedures‎ > ‎

Git

ViSLAB now support the use of git for version controlling your project.
This page describes the basic use of git to manage your project.

Background

ViSLAB's project server project.vislab.usyd.edu.au has git installed.  You can create a git repository in your own directory but this document also describe how to create shareable repository.

Config 

Before start using git, configure your own environment.  First setup your username and email address, which will be used when you commit your code:

$ git config --global user.name "yourusername"
$ git config --global user.email "your@email.address"

You can also set the colour setting so that the out can be easily read.

$ git config --global color.ui auto

All these setting will be saved in $HOME/.gitconfig  file.  It should now look like:

[user]
        netme = yourusername
        email = your@email.address
[color]
        ui = auto

Ignore files

When you working on a project, you might end up creating files, which do not need to be version controlled.  For example, backup files automatically generated by your editors, some intermediate files, which can always be re-generated from your main files.  You can specify the rules, which describes what sort of files should be ignored by git command.  You can have '.gitignore' file in your local working directory but you can also have .gitignore file in your home directory and register it as your global ignore rules.

Say, you have created the following ".gitignore" file in your home directory.

$ cat ~/.gitignore
*~
*.o
*.lo
*.la
.*~
.DS_Store
$

You can specify this file to be your global ignore by doing:

$ git config --global core.excludesfile ~/.gitignore



Creating Local Repository

This section describes creating a local git repository and manage your files locally.  First we create a directory called myProject.

$ mkdir myProject
$ cd myProject

Then we will put this directory under git's version control:

$ git init

This command will create a .git directory in myProject.  This .git directory is your local repository.  Now we will add our first file to be controlled:

$ touch README

At this stage README file is not under git's control.  If you type git status, you will get:

$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
# README
nothing added to commit but untracked files present (use "git add" to track)

This indicates that README is not tracked by git.

$ git add .

will add files, which are in "." directory (current directory and not under git's control.  This command does not actually commit those files to the repository.  In order to actually commit this "add" you would need to do:

$ git commit -m "Initial commit"

Summary

The following would the workflow when you're working with your local repository:
  1. create a file, edit a file
  2. check the status of the local working copy with 'git status'
  3. check the diff with 'git diff'
  4. once you finish editing, specify the files to be updated using
    • 'git add filename' or 'git add -u'
  5. commit your changes with 'git commit'



Working with Remote Repository

This section describes how you could work with the remote repository.  First, once you have decided the name of your project, which to be hosted on project.vislab.usyd.edu.au, ask ViSLAB admin to create the project directory on the Group folder.  Then ViSLAB admin will create an empty git repository for you.

Creating shared remote repository

This is done by ViSLAB admin (on project.vislab.usyd.edu.au):  (we assume that the new group has created and you're added to that group)

$ cd /Groups
$ sudo mkdir newGroupName; cd newGroupName
$ sudo mkdir newProjectName.git; cd newProjectName.git
$ sudo git init --bare --shared
$ cd ..
$ sudo chgrp -R newGroupName newProjectName.git


Create files locally and commit to the remote repository

Fist you can clone (checkout) the empty repo from the remote repository:

me% git clone ssh://project.vislab.usyd.edu.au/Groups/newGroupName/newProjectName.git

Then you can add a file:

me% emacs README
me% git add .

Then you can commit your changes to your LOCAL repository.
me% git commit -m "Added my comment"

At this stage, your commit is not on the remote repository (on project.vislab.usyd.edu.au).  In order to reflect your commit on the remote repository so that other people can clone your changes, you need to push your local repository changes to the remote master:

me% git push origin master

If your group members changed something on the remote repository, you can get the new changes and merge into your local repository by :
me% git pull
 

Summary

The following would the workflow when you're working with your remote repository:
  1. clone (checkout) the remote repository 
    • git clone ssh://project.vislab.usyd.edu.au/Groups/groupname/projectname.git
  2. create/edit file(s)
  3. check the status of the local working copy with 'git status'
  4. check the diff with 'git diff'
  5. once you finish editing, specify the files to be updated using
    • 'git add filename' or 'git add -u'
  6. commit your changes with 'git commit'
  7. propagate your commit to the remote repository with 'git push origin master'

Useful commands

git tag

You can tag your commit.  The following command will assign the specified tag to the commit just executed:
$ git tag tagname

Generating RSS Feed


Subpages (1): Generating RSS Feed
Comments