# Git - Formation à destination du projet Eman

Anne Garcia-Fernandez

► To cite this version:

Anne Garcia-Fernandez. Git - Formation à destination du projet Eman. Licence. Formation continue en Humanités numériques, En ligne, France. 2025, pp.18. hal-05010058

HAL Id: hal-05010058

https://hal.science/hal-05010058v1

Submitted on 28 Mar 2025

HAL is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_1.png" /></figure>
# Git - Focus pour Eman

branches, commandes utiles, logiciels
<figure><img src="image_2.png" /></figure>

S'y raccrocher...

BRANCHES
<figure><img src="image_3.png" /></figure>
<figure><img src="image_4.png" /><figcaption>GIT Branch and its
Operations.</figcaption></figure>

<figure><img src="image_5.png" /></figure>
## Rebase, aller de

A---B---C---D ← master

<figure><img src="image_6.png" /></figure>

E---F---G ← fonctionnalité

à

A---B---C---D ← master

<figure><img src="image_7.png" /></figure>

E---F---G ← fonctionnalité

<figure><img src="image_8.png" /></figure>
# Git Branch Cheatsheet

## List Branches

List Local
git branch

Local & Remote
git branch -a

List by Commit Date

git branch --sort=-committerdate

List by Merged Status

git branch --merged main
git branch --no-merged

List by Upstream & Last Commit

git branch -vv ← THIS IS NICE

## Create Branch

git branch new-branch
git checkout new-branch

... or ...

git checkout -b new-branch

<figure><img src="image_9.png" /></figure>

## Rename Branch

git branch -m old-branch new-branch
git push origin new-branch

## Switch Branch

Switch to Branch
git checkout existing-branch

Switch to Previous Branch
git checkout -

Interactive Switch Branch Alias

alias cb='git branch'

--sort=-committerdate |

fzf --header Checkout |

xargs git checkout'

<figure><img src="image_10.png" /></figure>

<figure><img src="image_11.png" /></figure>

## New Switch Command

Switch Branch
git switch existing-branch

Create Branch
git switch -c new-branch

This command is new as of v2.27.0 and was made to reduce confusion due to the many overloads of git checkout

## Delete Branch

Delete locale branch
git branch -d existing-branch

Delete remote branch
git branch -dr origin/existing-branch

Delete merged branches

git branch --merged main |
grep -v "main" |
xargs -n 1 git branch -d

main as
default
not
master

## Delete Stale Tracking

Test Run without Actually Pruning
git remote prune origin --dry-run

Delete locale branch
git remote prune origin

## GitHub Hub CLI

Sync branches & delete merged

hub sync

<figure><img src="image_12.png" /></figure>

I use this
all the time!
<figure><img src="image_13.png" /></figure>

À vous de choisir la vôtre !

# QUELQUES DIAGRAMMES ET FEUILLES
DE TRICHES
# Basic Git Commands

<figure><img src="image_14.png" /></figure>

<figure><img src="image_15.png" /></figure>
<figure><img src="image_16.png" /></figure>

Src :
https://medium.com/@humera.rk/top-25-
basic-git-commands-to-know-as-a-
software-tester-sdet-46d82335fba3
<figure><img src="image_17.png" /></figure>
# GIT CHEATSHEET

escape a git mess, step-by-step»
discover character entities at &what»

AN INTERACTION FROM NDP SOFTWARE

de en es fr it 日本語 pt ru vi 中文 简中

REMISE

ESPACE DE TRAVAIL

INDEX

DÉPÔT LOCAL

DÉPÔT DISTANT

clone <dépôt_distant>

pull <dépôt_distant> <référence>

branch --track <branche>
    <branche_distante>

fetch <dépôt_distant> <référence>

push

push <dépôt_distant> <branche>

push <dépôt_distant> <branche_1:branche_2>

branch -r

push <dépôt_distant> --
delete <branche>

git clone <dépôt_distant>

Télécharge le DÉPÔT_DISTANT et se positionne sur la TÊTE de sa branche main.
Common Git Commands

<figure><img src="image_18.png" /></figure>

- $git config

- $git init

- $git clone <path>

- $git add <file_name>

- $git commit

- $git status

- $git remote

- $git checkout <branch_name>

- $git branch

- $git push

- $git pull

- $git merge <branch_name>

- $git diff

- $git reset

- $git revert

- $git tag

- $git log
<figure><img src="image_19.png" /></figure>
# Git Cheat Sheet

## Setup

Set the name and email that will be attached to your commits and tags

```
$ git config --global user.name "Danny Adams"
$ git config --global user.email "my-email@gmail.com"
```

## Start a Project

Create a local repo (omit `<directory>` to initialise the current directory as a git repo)

```
$ git init <directory>
```

Download a remote repo

```
$ git clone <url>
```

## Make a Change

Add a file to staging

```
$ git add <file>
```

Stage all files

```
$ git add .
```

Commit all staged files to git

```
$ git commit -m "commit message"
```

Add all changes made to tracked files & commit

```
$ git commit -am "commit message"
```

## Basic Concepts

**main**: default development branch

**origin**: default upstream repo

**HEAD**: current branch

**HEAD^**: parent of HEAD

**HEAD~4**: great-great grandparent of HEAD

By @DoableDanny

## Branches

List all local branches. Add `-r` flag to show all remote branches. `-a` flag for all branches.

```
$ git branch
```

Create a new branch

```
$ git branch <new-branch>
```

Switch to a branch & update the working directory

```
$ git checkout <branch>
```

Create a new branch and switch to it

```
$ git checkout -b <new-branch>
```

Delete a merged branch

```
$ git branch -d <branch>
```

Delete a branch, whether merged or not

```
$ git branch -D <branch>
```

Add a tag to current commit (often used for new version releases)

```
$ git tag <tag-name>
```

## Merging

Merge branch a into branch b. Add `--no-ff` option for no-fast-forward merge

<figure><img src="image_20.png" /><figcaption>Head (ff)</figcaption></figure>

<figure><img src="image_21.png" /><figcaption>New Merge Commit (no-ff)</figcaption></figure>

```
$ git checkout b
```

```
$ git merge a
```

Merge & squash all commits into one new commit

```
$ git merge --squash a
```

## Rebasing

Rebase feature branch onto main (to incorporate new changes made to main). Prevents unnecessary merge commits into feature, keeping history clean

<figure><img src="image_22.png" /><figcaption>Rebased</figcaption></figure>

```
$ git checkout feature
```

```
$ git rebase main
```

Interactively clean up a branches commits before rebasing onto main

```
$ git rebase -i main
```

Interactively rebase the last 3 commits on current branch

```
$ git rebase -i Head~3
```

## Undoing Things

Move (`&/or` rename) a file & stage move

```
$ git mv <existing_path> <new_path>
```

Remove a file from working directory & staging area, then stage the removal

```
$ git rm <file>
```

Remove from staging area only

```
$ git rm --cached <file>
```

View a previous commit (READ only)

```
$ git checkout <commit_ID>
```

Create a new commit, reverting the changes from a specified commit

```
$ git revert <commit_ID>
```

Go back to a previous commit & delete all commits ahead of it (revert is safer). Add `--hard` flag to also delete workspace changes (BE VERY CAREFUL)

```
$ git reset <commit_ID>
```

## Review your Repo

List new or modified files not yet committed

```
$ git status
```

List commit history, with respective IDs

```
$ git log --oneline
```

Show changes to unstaged files. For changes to staged files, add `--cached` option

```
$ git diff
```

Show changes between two commits

```
$ git diff commit1_ID commit2_ID
```

## Stashing

Store modified & staged changes. To include untracked files, add `-u` flag. For untracked & ignored files, add `-a` flag.

```
$ git stash
```

As above, but add a comment.

```
$ git stash save "comment"
```

Partial stash. Stash just a single file, a collection of files, or individual changes from within files

```
$ git stash -p
```

List all stashes

```
$ git stash list
```

Re-apply the stash without deleting it

```
$ git stash apply
```

Re-apply the stash at index 2, then delete it from the stash list. Omit `stash@{n}` to pop the most recent stash.

```
$ git stash pop stash@{2}
```

Show the diff summary of stash 1. Pass the `-p` flag to see the full diff.

```
$ git stash show stash@{1}
```

Delete stash at index 1. Omit `stash@{n}` to delete last stash made

```
$ git stash drop stash@{1}
```

Delete all stashes

```
$ git stash clear
```

## Synchronizing

Add a remote repo

```
$ git remote add <alias> <url>
```

View all remote connections. Add `-v` flag to view `urls`.

```
$ git remote
```

Remove a connection

```
$ git remote remove <alias>
```

Rename a connection

```
$ git remote rename <old> <new>
```

Fetch all branches from remote repo (no merge)

```
$ git fetch <alias>
```

Fetch a specific branch

```
$ git fetch <alias> <branch>
```

Fetch the remote repo's copy of the current branch, then merge

```
$ git pull
```

Move (rebase) your local changes onto the top of new changes made to the remote repo (for clean, linear history)

```
$ git pull --rebase <alias>
```

Upload local content to remote repo

```
$ git push <alias>
```

Upload to a branch (can then pull request)

```
$ git push <alias> <branch>
```
https://ohshitgit.com/fr

<figure><img src="image_23.png" /></figure>

PAS SIMPLE QUAND MÊME... ET SI JE
ME RATE ?
# Liens pour aller plus loin

* [EN] https://git-scm.com/docs : doc officielle, un peu ardue... Mais complète

* [EN] https://www.w3schools.com/git/default.asp : tutoriel, toujours très pédagogique

* Un billet de blog pour commencer en douceur : https://elan.hypotheses.org/343 (et quelques autres okazou)
https://git-scm.com/downloads
https://git-scm.com/downloads/guis?os=windows

Exemples :

- https://tortoisegit.org/download/

- VSCode ou sa version libre : https://vscodium.com/

Conseil : utiliser tous le même !

<figure><img src="image_24.png" /></figure>

# EN PRATIQUE : LOGICIELS, LIGNE DE COMMANDE
# Annexe : fetch ou merge ?

* La commande **git fetch** va récupérer toutes les données des commits effectués sur la branche courante qui n'existent pas encore dans votre version en local. Ces données seront **stockées dans le répertoire de travail local mais ne seront pas fusionnées** avec votre branche locale. Si vous souhaitez fusionner ces données pour que votre branche soit à jour, vous devez utiliser ensuite la commande **git merge**.

* La commande **git pull** est en fait la commande qui regroupe les commandes **git fetch** suivie de **git merge**. Cette commande télécharge les données des commits qui n'ont pas encore été récupérées dans votre branche locale puis fusionne ensuite ces données.

https://www.journaldunet.fr/developpeur/developpement/1202965-git-pull-vs-git-fetch/