CommunityData:Git: Difference between revisions

From CommunityData
(→‎Cloning a repository: Note on git protocol)
(moves the .cc to .science)
Line 24: Line 24:
To clone a repository, run the following command:
To clone a repository, run the following command:


   git clone --recursive git@code.communitydata.cc:''REPOSITORY_NAME''
   git clone --recursive git@code.communitydata.science:''REPOSITORY_NAME''


Note that you need to use this SSH syntax rather than the [https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols git protocol] (e.g., <code>git://code.communitydata.cc/repo_name</code>), which doesn't have write permissions.
Note that you need to use this SSH syntax rather than the [https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols git protocol] (e.g., <code>git://code.communitydata.science/repo_name</code>), which doesn't have write permissions.


=== Creating a new repository ===
=== Creating a new repository ===
Line 70: Line 70:
First, you will need to clone the gitolite-admin repository
First, you will need to clone the gitolite-admin repository


  $ git clone git@code.communitydata.cc:gitolite-admin
  $ git clone git@code.communitydata.science:gitolite-admin


And then edit the file <code>conf/gitolite.conf</code>. To add a new project, simply create a new entry at the bottom of the file.
And then edit the file <code>conf/gitolite.conf</code>. To add a new project, simply create a new entry at the bottom of the file.
Line 82: Line 82:
</source>
</source>


would create a new repository at git@code.communitydata.cc:foo with aaron and mako as admins, and give jdfoote read-only access *once this file was saved, committed, and pushed*.
would create a new repository at git@code.communitydata.science:foo with aaron and mako as admins, and give jdfoote read-only access *once this file was saved, committed, and pushed*.


You could then go to wherever the files are that you would like to track, and add this repository as a remote, like so:
You could then go to wherever the files are that you would like to track, and add this repository as a remote, like so:
Line 88: Line 88:
$ cd foo
$ cd foo
$ git init
$ git init
$ git remote add origin git@code.communitydata.cc:foo
$ git remote add origin git@code.communitydata.science:foo
$ git add ./ # Adding everything to be tracked in git
$ git add ./ # Adding everything to be tracked in git
$ git commit  
$ git commit  
Line 97: Line 97:


<source lang='bash'>
<source lang='bash'>
$ git remote set-url origin git@code.communitydata.cc:foo
$ git remote set-url origin git@code.communitydata.science:foo
$ git push
$ git push
</source>
</source>

Revision as of 19:50, 14 August 2019

Setting Up Git

Once you've installed git, there are some configuration options which will make your life much easier. You can set them globally with the following commands:

git config --global alias.spull '!__git_spull() { git pull "$@" && git submodule sync --recursive && git submodule update --init --recursive; }; __git_spull'
git config --global status.submoduleSummary true

These two commands will ensure that git works a little better with submodules. Submodules are essentially git repositories that are buried inside other git repositories. For example, the wikiresearch repository currently uses the RCommunityData repository as a submodule. If you're working in a wiki like this, you'll want to use git spull instead of just git pull which will also check for and pull changes made in any of your submodules.

Gitolite Server

We have a private git server which uses gitolite to manage permissions for git repositories.

Dependencies

To get started, you will need a public SSH key. You can send your public key (usually ~/.ssh/id_rsa.pub) to a current administrator (probably Mako), and they can add you as a new user.

You will also need to have git installed.

Cloning a repository

"Cloning" a repository downloads the files, as well as the history, of a repository. It also creates a new git instance in that directory, so that you can commit changes to the code.

To clone a repository, run the following command:

 git clone --recursive git@code.communitydata.science:REPOSITORY_NAME

Note that you need to use this SSH syntax rather than the git protocol (e.g., git://code.communitydata.science/repo_name), which doesn't have write permissions.

Creating a new repository

To create a new repository, you will need to have admin rights. Currently, the administrators are Kaylea, Nate, Jeremy, Aaron, Mako, Sayamindu, and Jim. If you'd like to be an administrator, you should contact one of them!

Using git-annex to manage large files in git

Note Note: This is still experimental, and may go away. Don't put files in it without a backup.

Git is not a very good system for managing large files, which is a problem for us, since we often have large data files. Enter git-annex, a system that works in tandem with git and lets you store large files (but avoids using git as the data store). Our gitolite installation supports git-annex. To start using git-annex, install git-annex locally in your computer. Most GNU/Linux distributions has git-annex packages. Then, in your existing git repository execute the following initialization command:

$ git annex init

This needs to be done only once. To add a file, in your repository, run the following commands:

$ mkdir data
$ cp ~/largedata.csv.bz2 data/

You should encrypt the file if the data is not public. You can use GNU Privacy Guard to do the encryption, and have all your collaborators as recipients for the file. Once encrypted, execute the following commands to include and push the file to the server.

$ git annex add data/largedata.csv.bz2.gpg
$ git commit -m "Added data file"
$ git push --all
$ git annex copy --to origin

Once these commands are successful, your collaborators should be able to get the file with the following command (assuming that they have already run git annex init):

$ git annex get data/largedata.csv.bz2.gpg

Details for Administrators

Creating new repositories

If you are all already administrator, this describes how you will create a new repository.

First, you will need to clone the gitolite-admin repository

$ git clone git@code.communitydata.science:gitolite-admin

And then edit the file conf/gitolite.conf. To add a new project, simply create a new entry at the bottom of the file.

For example,

repo foo
    RW+ = aaron mako
    R   = jdfoote

would create a new repository at git@code.communitydata.science:foo with aaron and mako as admins, and give jdfoote read-only access *once this file was saved, committed, and pushed*.

You could then go to wherever the files are that you would like to track, and add this repository as a remote, like so:

$ cd foo
$ git init
$ git remote add origin git@code.communitydata.science:foo
$ git add ./ # Adding everything to be tracked in git
$ git commit 
$ git push --set-upstream origin master

If this project already exists in git, then it's even easier. Just change the remote, and push it.

$ git remote set-url origin git@code.communitydata.science:foo
$ git push

Adding new users

To add new users, simply add their public key to the keydir/ directory, renamed as username.pub. The persons username (as called in the code/gitolite.conf file) will be whatever the username in the filename above is.