The official freesurfer source code repository can be found on the page:

Initial Setup

The initial setup for contributing to the freesurfer repository involves the user forking off the freesurfer GitHub repo, cloning the users fork into a local repository, then adding the freesurfer repository as an upstream remote. This setup is illustrated below, followed by a more detailed description of the steps involved:


  1. Sign up for a github account if you don't already have one. When creating an account, you can use any email you want, but developers at the Martinos Center should eventually link their <username> email to their GitHub account. This can be done after the account is created.

  2. From your GitHub account, fork the freesurfer project repository by clicking on the 'Fork' button near the top right-hand of the page. This creates a copy of the freesurfer code base under your account on the GitHub server.


  3. On your local machine, make a clone of your freesurfer repository (the one you forked):
    git clone<git_username>/freesurfer.git
  4. Add the main freesurfer repository as a remote to the local clone you already have on your local disk, and set it as the upstream remote:

    git remote add upstream
  5. Type the following command to make sure you have the proper setup:
    git remote -v
    origin (fetch)
    origin (push)
    upstream (fetch)
    upstream (push)

    Note: If you are seeing an "X11 forwarding request failed" warning when communicating with github, this is caused by a global ssh setting in /etc/ssh/ssh_config. To prevent these forwarding requests to github servers, add the following lines to your ~/.ssh/config

    Host *
        ForwardX11 no

Committing Changes

To contribute the the freesurfer code base, users should 1) Update their code 2) Create a new branch off the dev branch 3) Commit the changes and push the branch to their fork (origin) 4) Submit a Pull Request into freesurfer/dev to get those changes into the freesurfer code base. This workflow is illustrated below, followed by a more detailed description of the steps involved:


  1. When you start to make changes, the first thing to do is make sure you are in the dev branch and everything is up to date with the upstream repo:
    git branch
    * dev
    git pull upstream dev
  2. Then create a new branch (off dev) to hold your work and start making changes. Ideally, use a prefix signaling the purpose of the branch:

    git checkout -b nf-my-feature
    • nf- for new features

    • bf- for bug fixes

    • rf- for refactoring

    • doc- for documentations contributions.

    • test- for test related contributions.

  3. Work on this copy on your computer using Git to do the version control. When you're done editing, commit the files to the local branch and push the branch to origin (your personal GitHub account):

    git add <modified_files>
    git commit -m "Commit message"
    git push origin nf-my-feature
  4. Finally, go to the GitHub web page of your fork of the freesurfer repo, and click Pull request to send your changes to the maintainers for review. Make sure you are submitting your newly created branch into the freesurfer/dev. This will send an email to the committers. You can commit new changes to this branch and keep pushing to your remote -- github automagically adds them to your previously opened Pull request.



  5. Once you have submitted your pull request for the nf-my-feature, it is best practice to switch back into dev and do an update. You are then free to start the process anew (i.e. create a new branch, commit changes, submit pull request):

    git checkout dev
    git pull upstream dev

Cleanup steps (Optional)

  1. Once your pull request is accepted (you should get an email), feel free to delete the branch you created:
    git branch -D nf-my-feature


Instructions on how to further work with the freesurfer source code, including building, testing, and adding a binary to the tree, should consult the Freesurfer Developers Guide:

Data files

A default clone of the repo will only give the user source code. Data files are stored in git annex, exist as broken symlinks by default, and need to be specially requested. To request a datafile, first add the remote repository that stores all the freesurfer data files (you only need to this once):

Your list of remote repositories should now look something like this:

Now you can just specifically request whatever datafile you need:

Or just get everything (Not recommended):

For more information on how to work with the data files and git annex in general, see the following page:


git checkout dev
git fetch upstream
git merge upstream/dev
git push origin

Freesurfer_github (last edited 2017-05-19 11:47:36 by ZekeKaufman)