5 Git And GitHub
Git and GitHub are used in Shen Lab to organize code, track project history, collaborate with others, and make analyses easier to review and reproduce. Every lab member who writes code should learn the basic Git workflow.
Git is the version-control system. GitHub is an online platform for hosting Git repositories, reviewing changes, managing issues, and collaborating with lab members or external collaborators.
5.1 What To Install
New members should install:
- Git;
- a GitHub account;
- GitHub Desktop, optional but useful for beginners;
- an editor such as RStudio or Visual Studio Code;
- command-line access through Terminal, PowerShell, or another shell.
After installation, check Git from the command line:
5.2 GitHub Account
Create or prepare a GitHub account before working on lab code. Use an account name and profile that collaborators can recognize.
Recommended setup:
- add your full name or recognizable display name;
- add your NTU email or another professional email;
- enable two-factor authentication;
- set up SSH keys or another secure authentication method;
- ask the PI or repository owner for access to the relevant organization or repository.
Do not share your GitHub password, personal access token, SSH private key, or recovery codes with anyone.
5.3 Basic Workflow
Most lab projects use a simple workflow:
- clone the repository;
- create or switch to the correct branch;
- pull the latest changes;
- edit files;
- check what changed;
- commit with a clear message;
- push changes to GitHub;
- open a pull request if review is needed.
Common commands:
git clone REPOSITORY_URL
git status
git pull
git add FILE
git commit -m "Describe the change"
git pushIf you are unsure about a shared repository, ask your mentor before pushing.
5.4 Branches
Branches allow you to work on changes without immediately changing the main version of a project.
Good practice:
- use a new branch for substantial edits;
- keep branch names short and descriptive;
- pull the latest changes before starting;
- avoid doing unrelated work in the same branch;
- delete merged branches when they are no longer needed.
Example:
5.5 Commits
A commit should represent a clear unit of work. Good commit messages make project history easier to understand.
Good commit messages:
- describe what changed;
- are specific enough to be useful later;
- avoid vague messages such as
update,fix, orfinal; - separate unrelated changes into different commits when possible.
Examples:
Add sample metadata validation script
Update metabolomics QC figure
Fix file path in preprocessing workflow
5.6 Pull Requests
Pull requests are used to review and discuss changes before merging them.
A good pull request should include:
- a short summary of the change;
- why the change was needed;
- files or workflows affected;
- tests, checks, or commands that were run;
- notes about limitations or remaining work.
For manuscripts, websites, packages, or shared analysis pipelines, pull requests help others review changes before they affect the main project.
5.7 What Not To Commit
Never commit:
- passwords;
- API keys;
- access tokens;
- SSH private keys;
- identifiable human-subject information;
- unpublished sensitive data unless the repository is explicitly approved for it;
- large raw data files unless the project has a clear storage policy;
- temporary files such as
.DS_Store,.RData,.Rhistory, or cache folders.
Use .gitignore to keep local or generated files out of version control.
5.8 GitHub Issues
GitHub Issues can be used to track:
- bugs;
- analysis tasks;
- website updates;
- documentation needs;
- discussion points;
- project to-do items.
Write issues clearly. Include background, expected outcome, current problem, and relevant files or links.
5.9 Lab Practice
For lab projects:
- keep code in the agreed repository;
- keep data in the approved storage location;
- document how to rerun important analyses;
- avoid changing shared code without communicating with the project owner;
- use pull requests for changes that affect other people;
- ask before making destructive changes to shared branches or repositories.
If a repository contains unpublished work, collaborator data, or manuscript materials, confirm sharing and visibility settings with the PI.
Shen Lab 使用 Git 和 GitHub 管理代码、追踪项目历史、协作开发,并让分析更容易审阅和复现。所有写代码的实验室成员都应掌握基本 Git 工作流程。Git 是版本控制系统,GitHub 是托管 Git repository、review changes、管理 issues 和协作的平台。
新成员应安装 Git,准备 GitHub 账号,并根据需要安装 GitHub Desktop、RStudio 或 Visual Studio Code 等编辑器。安装后在命令行检查:
请使用容易被合作者识别的 GitHub 账号,添加真实姓名或清楚的 display name,绑定专业邮箱,开启 two-factor authentication,并设置 SSH key 或其他安全认证方式。需要访问实验室 repository 时,请联系 PI 或 repository owner。
不要分享 GitHub 密码、personal access token、SSH private key 或 recovery codes。
常见流程是:clone repository,切换或创建 branch,pull 最新变化,编辑文件,检查改动,commit,push,并在需要 review 时创建 pull request。
git clone REPOSITORY_URL
git status
git pull
git add FILE
git commit -m "Describe the change"
git push如果不确定共享 repository 的规则,请先问 mentor 再 push。
Branch 可以让你在不直接影响主版本的情况下工作。重要改动应新建 branch,名称简短清楚,开始前先 pull 最新版本,不要把无关改动混在同一个 branch 中。合并后不再需要的 branch 可以删除。
Commit 应代表一个清楚的工作单元。好的 commit message 应说明改了什么,避免只写 update、fix、final。无关改动尽量分开提交。
Add sample metadata validation script
Update metabolomics QC figure
Fix file path in preprocessing workflow
Pull request 用于合并前 review 和讨论改动。好的 PR 应包括改动摘要、为什么需要修改、影响的文件或流程、运行过的测试或检查,以及已知限制或后续工作。对 manuscript、网站、package 或共享分析管线,PR 尤其重要。
不要提交密码、API keys、access tokens、SSH private keys、可识别 human-subject information、未经批准的敏感未发表数据、大型 raw data,以及 .DS_Store、.RData、.Rhistory、cache folders 等临时文件。使用 .gitignore 管理本地文件和生成文件。
GitHub Issues 可用于追踪 bugs、分析任务、网站更新、文档需求、讨论事项和 project to-do items。Issue 应写清背景、预期结果、当前问题,以及相关文件或链接。
实验室项目应把代码放在约定 repository,数据放在批准存储位置,重要分析说明如何重新运行。修改共享代码前应和项目负责人沟通;影响他人的改动应使用 pull request。不要在未确认的情况下对共享 branch 或 repository 做破坏性操作。
如果 repository 包含未发表工作、合作者数据或 manuscript 材料,请和 PI 确认共享和可见性设置。
遇到 Git 或 GitHub 问题时,请提供 repository 名称、branch 名称、运行的命令、完整错误信息、git status 输出,以及你原本想完成的操作。然后再向 mentor、相关实验室成员或 PI 求助。