Basics in git, working alone

Marie-Pierre Etienne

https://github.com/MarieEtienne/reproductibilite

2025-09-10

Introduction to git

What is it?

  • Developed by Linus Torvalds: “I’m an egotistical bastard, and I name all my projects after myself. First Linux, now git.”
  • Git is a version control system (the most widely used today).
  • It allows tracking all changes made to code since its creation.
  • Git is incredibly efficient.

Starting from an existing directory

Cloning an existing reprository

This means copy locally on your computer the content of a repository which means

  • copy the actual code and text contents
  • copy the history of all changes

Before using Git, we need basic bash commands

First element - navigating using bash command

Navigating Directories in the Terminal / Git Bash

  1. Checking where you are
$ pwd
/home/marie/projects
  1. Listing files
ls -l #→ long listing
ls -a #→ include hidden files
  1. Moving between directories
Action Linux/macOS/Git Bash Windows Command Prompt
Go to a directory cd folder_name cd folder_name
Go up one level cd .. cd ..
Go to home cd ~ cd %USERPROFILE%
Absolute path cd /path/to/folder cd C:\path\to\folder

First element - navigating using bash command

  1. Create a directory
mkdir my_git_dir
  1. Removing files or directory
rm my_file
rmdir my_dir #remove an empty dir
rm -rf my_dir #remove a directeory and everything inside ! Careful
  1. Quick tips

Use Tab for autocomplete paths and filenames.

Paths on Git Bash use /, even on Windows (/c/Users/...).

Exercise

  • Go to your home directory (/home/loginin Linux, probably somethin like C:/Users/yourusername in Windows)

  • Create a directory named git, where you will store all your git projects

  • Jump within this directory

  • list the files contained in this directory

  • Create a test_dir directory

  • Jump outside the git directory

  • Remove the git directory and everything it contains

  • Create a directory named git, where you will store all your git projects

Cloning an existing reprository

Go to your git Directory and write

git clone git@github.com:MarieEtienne/stats-reminders.git

What is happening ?

ls
cd stats-reminders
ls

Where to find this magical address to clone

Navigate to the repository you want to clone On the main page, click on the “Code” green button, be sure to select SSH and copy paste the address.

Reviewing the code development

git log
git log --oneline
gitk

Forking an existing repository

What is forking?

Forking creates your own copy of someone else’s repository in your GitHub account. This lets you experiment with changes without affecting the original project. How to fork a repo:

How

Navigate to the repository you want to fork on GitHub Click the “Fork” button in the top-right corner of the repository page Choose where to fork it - usually to your personal account Wait a moment - GitHub will create the copy in your account

What happens next:

You’ll have a complete copy of the repo in your GitHub account You can clone this forked version to your local machine using git clone Make changes, commit them, and push back to your fork If you want to contribute back to the original project, you can create a pull request

Key points

Your fork is independent of the original repo You have full control over your forked version The original repo remains unchanged unless you submit a pull request that gets accepted You can sync your fork with the original repo later if it gets updated

This workflow is essential for contributing to open-source projects or collaborating on code when you don’t have direct write access to the original repository.

Exercise

Creating new content

Your first commit

  • Open the file Penguins_chapter.qmd and add your name and the list of authors, then save your file.
  • Type the command git log in the console.
  • Enter the following commands:
git status # project status
git diff
  • Type the command git add penguins.Rmd, then repeat the previous commands.

  • Type the command git commit -m "Added an author", and once again check the project status.

  • Check the project on Github

  • Type the command git push", and once again check the project on Github