Editing CommunityData:Git

From CommunityData

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
Wondering why this is a topic to care about? Check this [https://about.gitlab.com/topics/version-control what is version control?] article.
== Setting Up Git ==


== Getting Access to the CDSC Git Repository ==
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:


If you need access to the CDSC Git Repository, you should ask on the [[CommunityData:IRC|#communitydata IRC channel]] for access. If you need access to a specific repository only, mention which one. While you likely already know which repo you want access to, you can find the public ones on [https://code.communitydata.science/ code.communitydata.science], and a complete list of all of them <code>conf/gitolite.conf</code> file in the <code>gitolite-admin</code> git repository. If you are a new CDSC member, mention that you need to be added to the <code>@collective</code> group in Gitolite. Anybody in the collective who uses the Git repository will be able add you.
  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


== Install Git==
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 <code>wikiresearch</code> repository currently uses the <code>RCommunityData</code> repository as a submodule. If you're working in a wiki like this, you'll want to use <code>git spull</code> instead of just <code>git pull</code> which will also check for and pull changes made in any of your submodules.


To get started, you will need to '''install git'''. Doing so requires different steps depending on your operating system. Basic instructions available from [https://git-scm.com/downloads the Git website].
== Gitolite Server ==


You will also likely need to set it up so it knows what your name and email address is. You can do that like:
We have a private git server which uses [http://gitolite.com/gitolite/index.html gitolite] to manage permissions for git repositories.


<source lang='bash'>
=== Dependencies ===
$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com
Again
</source>


Note that RStudio also has Git integration now. Instructions and details available via [https://support.rstudio.com/hc/en-us/articles/200532077-Version-Control-with-Git-and-SVN RStudio support documentation].
To get started, you will need a [https://help.github.com/articles/generating-ssh-keys/ 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.


== Configuring Git for submodules ==
You will also need to have git installed.


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:
=== Cloning a repository ===


git config --global alias.spull '!__git_spull() { git pull "$@" && git submodule sync --recursive && git submodule update --init --recursive; }; __git_spull'
"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.
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 <code>wikiresearch</code> repository currently uses the <code>RCommunityData</code> repository as a submodule. If you're working in a repository like this, you'll want to use <code>git spull</code> instead of just <code>git pull</code> which will also check for and pull changes made in any of your submodules.
To clone a repository, run the following command:


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


We have a private git server which uses [https://about.gitea.com/ gitea] to manage permissions for git repositories. It's like a private Github server that hosts our respositories, but just ours, and on our server.
=== Creating a new repository ===


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


We have a private git server which uses [http://gitolite.com/gitolite/index.html gitolite] to manage permissions for git repositories. It's like a private Github server that hosts our respositories, but just ours, and on our server.
=== Using git-annex to manage large files in git ===


=== SSH Keys ===
{{note}} This is still experimental, and may go away. Don't put files in it without a backup.


Once you've got git installed, you will also need a [https://help.github.com/articles/generating-ssh-keys/ public SSH key]. You can send your public key (usually ~/.ssh/id_rsa.pub) to a current administrator (see the list of administrators below on this page), and they can add you as a new user.
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 [https://git-annex.branchable.com/walkthrough/ 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:
 
<source lang='bash'>
$ git annex init
</source>


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


"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.
<source lang='bash'>
$ mkdir data
$ cp ~/largedata.csv.bz2 data/
</source>


To clone a repository, run the following command:
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 clone --recursive git@code.communitydata.science:''REPOSITORY_NAME''
<source lang='bash'>
$ git annex add data/largedata.csv.bz2.gpg
$ git commit -m "Added data file"
$ git push --all
$ git annex copy --to origin
</source>
Once these commands are successful, your collaborators should be able to get the file with the following command (assuming that they have already run <code>git annex init</code>):


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.
<source lang='bash'>
$ git annex get data/largedata.csv.bz2.gpg
</source>


=== Creating a new repository ===
=== Details for Administrators ===
==== Creating new repositories ====


To create a new repository, you will need to have admin rights. Currently, everyone in the collective group is an administrator.
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
First, you will need to clone the gitolite-admin repository


  $ git clone git@code.communitydata.science:gitolite-admin
  $ git clone git@code.communitydata.cc: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 68: Line 80:
</source>
</source>


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*.
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*.
 
In order to actually create the repository you need to:
 
# Save the file (i.e., with text editor)
# Add the file with (with <code>git add conf/gitolite.conf</code>)
# Commit the file (with <code>git commit</code>) (this will put you into a text editor where you can add a commit message)
# Push the file back to the server (with <code>git push</code>)
 
=== Pushing data into a new repository on the server from a local git repository you already have ===


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:
<source lang='bash'>
<source lang='bash'>
$ cd foo
$ cd foo
$ git remote add origin git@code.communitydata.science:foo
$ git init
$ git push --set-upstream origin main
$ git remote add origin git@code.communitydata.cc:foo
$ git add ./ # Adding everything to be tracked in git
$ git commit
$ git push --set-upstream origin master
</source>
</source>


Line 89: Line 95:


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


To add new users, simply add their public key to the <code>keydir/</code> directory, renamed as <code>username.pub</code>. The persons username (as called in the <code>code/gitolite.conf</code> file) will be whatever the username in the filename above is.
To add new users, simply add their public key to the <code>keydir/</code> directory, renamed as <code>username.pub</code>. The persons username (as called in the <code>code/gitolite.conf</code> file) will be whatever the username in the filename above is.
== Using git-annex to manage large files in git ==
{{note}} This is still experimental, and may go away. Don't put files in it without a backup.
=== Getting Set Up ===
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 [https://git-annex.branchable.com/walkthrough/ 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 have git-annex packages. If you're on a Mac, in Terminal.app, try the instructions from Homebrew: https://formulae.brew.sh/formula/git-annex.
=== Setting Up Your Repo To Use Annex ===
Then, in your existing git repository execute the following initialization command:
 
<source lang='bash'>
$ git annex init
</source>
This needs to be done only once. To add a file, in your repository, run the following commands:
<source lang='bash'>
$ mkdir data
$ cp ~/largedata.csv.bz2 data/
</source>
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.
<source lang='bash'>
$ git annex add data/largedata.csv.bz2.gpg
$ git commit -m "Added data file"
$ git push --all
$ git annex copy --to origin
</source>
=== Using an Existing Annex Repo ===
Once these commands are successful, your collaborators should be able to get the file with the following command (assuming that they have already run <code>git annex init</code>):
<source lang='bash'>
$ git annex get data/largedata.csv.bz2.gpg
</source>
Once you've encrypted non-public data, git-annex is easy to use using the webapp.
<source lang='bash'>
$ git annex webapp
</source>
Please note that all contributions to CommunityData are considered to be released under the Attribution-Share Alike 3.0 Unported (see CommunityData:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:

Cancel Editing help (opens in new window)

Template used on this page: