Skip to content

Commit e932ca1

Browse files
Merge pull request #40 from phuse-org/38-git-first-step
fc
2 parents 03c7d1c + ea74245 commit e932ca1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+326
-0
lines changed
Lines changed: 326 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,326 @@
1+
---
2+
title: "First step on git"
3+
subtitle: "Working in collaboration with git and github"
4+
author: "Hugo Bottois & Alex Assuied"
5+
date: "2025-07-31"
6+
categories: [Git, Versionning]
7+
image: "image.jpg"
8+
---
9+
10+
# Introduction
11+
12+
[Git](https://git-scm.com/) is a distributed version control system designed for ensuring code integrity and maintaining a complete history of revisions.
13+
14+
It is an essential tool for many developers, allowing them to track changes, collaborate with others, and manage code in a structured manner.
15+
16+
This documentation aims to provide a comprehensive understanding of Git's core functionality and good practices for clear and efficient collaboration during coding projects.
17+
18+
This documentation is made for an audience with a basic understanding of git.
19+
20+
Git can be used both through Terminal command line and `RStudio` programming interface or other tools (`Github Desktop`).
21+
22+
Please be aware that certain operations are not fully supported or are only partially covered by the RStudio interface. In these cases, utilizing the command line may be the only viable approach.
23+
24+
::: callout-important
25+
The present document focuses on general practices for using Git.
26+
27+
As our understanding and methodologies evolve, specific guidance tailored to clinical standards, project requirements, and FDA compliance in relation to source code and data management in clinical research will be developed and shared.
28+
:::
29+
30+
# Installation
31+
32+
If you never used `Git` or `GitHub` before, start by creating a GitHub account and configuring Git.
33+
34+
::: callout-important
35+
GitHub is a platform for git-managed projects that allows developers to store, manage, and track changes to their code to nurture collaboration.
36+
37+
Other alternative such as Gitlab and Bitbucket exist.
38+
:::
39+
40+
**To create a github account:**
41+
42+
You can create a github account [Here](https://github.com/)
43+
44+
**To install git:**
45+
46+
You can install Git on your local machine [Here](https://git-scm.com/downloads)
47+
48+
Git is often already installed in internal company environments.
49+
50+
## Initial setup: Configuration SSH key on RStudio and GitHub
51+
52+
When integrating `GitHub` with `RStudio`, we need to establish a secure connection.
53+
54+
`SSH` (Secure Shell) keys are the preferred method for this secure authentication. SSH keys operate on a key pair system:
55+
56+
`Private Key:` This is kept secret on your computer.
57+
58+
`Public Key:` This is shared with services like `GitHub`.
59+
60+
When you use Git to push code or pull changes from GitHub, it checks your SSH key. If your public key matches the private key on your computer, GitHub knows it's really you. This is safer than an username/password because the keys are much harder to hack.
61+
62+
*Only if you do not have SSH key*
63+
64+
To securely and conveniently interact with `GitHub` repositories in `RStudio`, you should generate an `SSH` key and add it to your GitHub account, which allows passwordless authentication for Git operations.
65+
66+
- On RStudio, Create a SSH key in Tools \> Global Option \> Git/SVN \> "Create RSA SSH key"
67+
68+
![](img_git/ssh_git_1_create.PNG){fig-align="center" width="381"}
69+
70+
Copy and paste the key into your GitHub profile as:
71+
72+
- Copy your ssh key in RStudio: Tools \> Global Option \> Git/SVN \> "View public key"
73+
74+
![](img_git/ssh_git_1_copy.PNG){fig-align="center" width="398"}
75+
76+
- Go to your `GitHub` account and paste your key in: profile: Settings \> SSH and GPG keys \> New SSH key
77+
78+
The SSH begins with 'ssh-rsa', 'ecdsa-sha2-nistp256', 'ecdsa-sha2-nistp384', 'ecdsa-sha2-nistp521', 'ssh-ed25519', 'sk-ecdsa-sha2-nistp256\@openssh.com', or 'sk-ssh-ed25519\@openssh.com'
79+
80+
- Do not forget to add a Title
81+
82+
- Add SSH key
83+
84+
![](img_git/ssh_git_3.PNG){fig-align="center"}
85+
86+
::: callout-note
87+
After installing Git, you might need to configure your username and email address.
88+
89+
Open a terminal (or Git Bash on Windows).
90+
91+
Configure your user name and email address by running:
92+
93+
``` {.bash filename="Terminal"}
94+
git config --global user.name "Your Name"
95+
git config --global user.email "[email protected]"
96+
```
97+
98+
Use the email associated with your GitHub account.
99+
100+
You can check your configuration setting with:
101+
102+
``` {.bash filename="Terminal"}
103+
git config --global --list
104+
```
105+
106+
On RStudio, go to Tools -\> Global Options -\> Git/SVN and make sure RStudio detected the Git executable.
107+
108+
![](img_git/git_config.png){width="326"}
109+
110+
If not, you may need to manually specify the path to the Git executable manually.
111+
:::
112+
113+
The next section will describe basic operation for git code versioning and project hosted on GitHub
114+
115+
# Git and Github: first steps
116+
117+
`Git` is the technology allowing you to use version system for your project. A project tracked with git is called a `repository`
118+
119+
`Github` is a host that allowing you to store your project manage with git (a `repository`!) along with others services.
120+
121+
You can either create a new repository from scratch or join a project that already have a github repository. Here how you below do it.
122+
123+
## Github repository creation
124+
125+
To create a new remote repository you can either:
126+
127+
- Create a local repository locally via Rstudio and send it to github (This is called a `Push`).
128+
129+
- Create a remote repository on `GitHub` import it locally on your computer (This is called a `Clone`).
130+
131+
## Clone the Repository in RStudio
132+
133+
Cloning a repository will download the remote project locally
134+
135+
- On RStudio interface: Files \> new project \> Global Option create a new project and select the `Version control` option
136+
137+
![](img_git/1_create_local_project.PNG)
138+
139+
- Select Git option
140+
141+
![](img_git/2bis_select_git_2.PNG)
142+
143+
- Add the link to the `GitHub` repository in the repository URL
144+
145+
![](img_git/3_import_project.PNG)
146+
147+
::: callout-important
148+
You can clone using SSH (often required by companies) or HTTPS.
149+
:::
150+
151+
RStudio run this command for us to clone the remote repository
152+
153+
``` {.bash filename="Terminal"}
154+
git clone REPO_URL
155+
```
156+
157+
![](img_git/4_git_import.PNG)
158+
159+
When a new project is created, RStudio automatically:
160+
161+
- Initiates Git and fetches all remote branches and pulls the default branch (e.g. master) into your directory.
162+
163+
- Creates a project file (with an .Rproj extension) within the project directory. This file contains various project options and can also be used as a shortcut for opening the project directly from the filesystem.
164+
165+
- Creates a hidden directory (named .Rproj.user) where project-specific temporary files (e.g. auto-saved source documents, window-state, etc.) are stored. This directory is also automatically added to .Rbuildignore, .gitignore, etc. if required.
166+
167+
- Loads the project into RStudio and display its name in the Projects toolbar (which is located on the far right side of the main toolbar)
168+
169+
## Create a New Branch
170+
171+
In `Git`, creating `branches` is a key strategy for effective collaboration. A branch is a copy of the main codebase from the default branch (commonly called `main` or `master` branch), allowing developers to work on new features separately without affecting the primary code.
172+
173+
When the feature on this branch is ready, it can be carefully reviewed and tested, then merged into the main codebase.
174+
175+
It's common to have one branch per feature, often corresponding to a single developer's work.
176+
177+
Branch names should be concise, explicit, and should always be in lowercase to ensure clarity and consistency.
178+
179+
To create your first local branch :
180+
181+
![](img_git/11_first_branch.PNG)
182+
183+
RStudio run this command for us to create a new branch:
184+
185+
``` {.bash filename="Terminal"}
186+
git checkout -b BRANCH_NAME
187+
```
188+
189+
You should be able to see a new branch now Here :
190+
191+
![](img_git/12_first_branch_command.PNG)
192+
193+
::: callout-tip
194+
Always try to be aware on which branch your working on
195+
:::
196+
197+
## BIS:Create New Branch from an github Issue
198+
199+
It is strongly recommended to create a branch from a `github Issue`.
200+
201+
A `GitHub issue` is a tool used within the `GitHub` platform to track ideas, enhancements, tasks, or bugs. It acts as a discussion forum for managing and discussing these topics among team members.
202+
203+
Basically, this is a way to provide feedback for collaboration and organization in the project.
204+
205+
To create an issue, follow these steps:
206+
207+
- Click on report an issue/edit this page
208+
209+
![](img_git/create_issue.PNG)
210+
211+
This will send you to the github repository in the Issues session.
212+
213+
- Create a **GitHub Issue**: Navigate to the project's GitHub page and click on the `Issues` tab. There, you can create a new issue. See the example below for reference:
214+
215+
![](img_git/Issue_github.PNG)
216+
217+
**Before submitting an issue, please:**
218+
219+
- Check for **Existing Issues**: Ensure that a similar issue doesn't already exist.
220+
221+
- Use Descriptive **Titles**: Keep your issue titles concise yet descriptive (example: add_spaghetti_recipe)
222+
223+
- Add an appropriate **labels** (bug, documentation)
224+
225+
- Assign someone to this Issue
226+
227+
![](img_git/issue_label.PNG){fig-align="left" width="642"}
228+
229+
- Submit your issue
230+
231+
::: callout-note
232+
Privacy Note: Be aware that your issue will be publicly visible.
233+
:::
234+
235+
Now lets create a `branch` from `github Issue`:
236+
237+
![](img_git/create_branch_from_issue.PNG){width="200"}
238+
239+
Then, create a branch from the `Github Issues` as below:
240+
241+
![](img_git/create_branch_from_issue_2.PNG){width="200"}
242+
243+
## Commit message
244+
245+
Each `commit` is associated with a `commit message` describing the committed changes.
246+
247+
In the git tab, click on "Commit". Select the modified file and click on "commit" with a message to commit your change.
248+
249+
Always try to Commit changes with a meaningful message as this is better for having a clear git history and help collaborators/reviewers understand the code changes.
250+
251+
![](img_git/8_first_commit.PNG)
252+
253+
RStudio runs this command for us
254+
255+
``` {.bash filename="Terminal"}
256+
git add .
257+
git commit -m MEANINGFUL_MESSAGE
258+
```
259+
260+
This is the best way to communicate context about a change to other developers (or to yourself) working on that project now or in the future.
261+
262+
A Git repository is not a backup system and randomly committing code changes to capture the current state of your work could make the code history difficult to comprehend.
263+
264+
Avoid treating Git as a backup tool by committing unstructured or excessive snapshots
265+
266+
Commits should be clear, concise, and organized into logical units.
267+
268+
How to Write Good Commit Message:
269+
270+
```
271+
Capitalized, short (50 chars or less) summary
272+
273+
More detailed explanatory text, if necessary. Wrap it to about 72 characters or so. In some contexts, the first line is treated as the subject of an email and the rest of the text as the body. The blank line separating the summary from the body is critical (unless you omit the body entirely); tools like rebase can get confused if you run the two together.
274+
275+
Write your commit message in the imperative: "Fix bug" and not "Fixed bug" or "Fixes bug." This convention matches up with commit messages generated by commands like git merge and git revert.
276+
277+
Further paragraphs come after blank lines.
278+
279+
Bullet points are okay, too
280+
281+
Typically a hyphen or asterisk is used for the bullet, followed by a single space, with blank lines in between, but conventions vary here
282+
283+
Use a hanging indent
284+
285+
If you use an issue tracker, add a reference(s) to them at the bottom, like so:
286+
287+
Resolves: #123
288+
```
289+
290+
[source](https://www.freecodecamp.org/news/writing-good-commit-messages-a-practical-guide/)
291+
292+
## Create a Pull Request
293+
294+
When a feature is completed on a branch, it is ready to be integrated into the common codebase on the default branch (commonly called `main` or `master` branch). This integration process requires the creation of a `Pull Request` (PR).
295+
296+
A Pull Request, or PR, is essentially a proposal to merge changes from one branch into the master branch. This merging process typically takes place after the changes have been reviewed and approved by another coder, who is designated as the reviewer.
297+
298+
The purpose of this procedure is to prevent errors from being merged into the master branch, thereby maintaining the integrity and quality of the codebase.
299+
300+
- Request the PR with `Compare & pull request`
301+
302+
![](img_git/18_update_after_push.PNG)
303+
304+
- Assign a reviewer
305+
306+
![](img_git/19_bis_add_reviewer.PNG)
307+
308+
## Documentation
309+
310+
Each project requires documentation to help users and contributors understand what the project is about, how to set it up, and how to use it.
311+
312+
This makes it easier for people to use the project and contribute to it. github repository project generally contains:
313+
314+
### Readme
315+
316+
`README` is a document used in a repository to provide essential information about the project. It typically includes a brief introduction to the project, setup instructions, usage guidelines, contribution process, licensing details, and contact information for the maintainers.
317+
318+
The goal of this document is to allow a new user to quickly understand an overview and any critical information about the project stored in a convenient place.
319+
320+
### .gitignore
321+
322+
`.gitignore` is a text file that tells Git which files or directories to ignore in a project. This could include sensitive information (API key, password) or unwanted files.
323+
324+
::: callout-important
325+
NEVER commit sensitive information: Ensure that you haven't accidentally included any confidential data, API keys, passwords, or other secrets in your code. Otherwise, this information will be visible in the Git history.
326+
:::
10 KB
241 KB
260 KB
180 KB
248 KB
264 KB
137 KB
169 KB
199 KB

0 commit comments

Comments
 (0)