Site Tools


informatique:git

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
informatique:git [2024/11/18 18:08] yahikoinformatique:git [2024/12/08 16:04] (current) yahiko
Line 1: Line 1:
-====== Bloc note GIT ====== +====== Git ======
-J'ai commencé à utiliser git il y a peu pour stocker et gérer les scripts que je réalise pour mon activité pro. Je vais mettre ici les commandes usuelles que j'ai utilisé.+
  
- * https://tedomum.net/training/git/ +Bloc note de commandes concernant GitParce que concrètement, j'y vais un peu pifFaudrait que je lise la doc, un jour.
- * https://forge.tedomum.net/help/gitlab-basics/start-using-git.md+
  
-===== S'identifier ===== +{{ :informatique:dog-no-ideae.jpg?nolink& 400 | I have no idea what I'm doing}}
-<code shell> +
-git config --global user.name "your_username" +
-git config --global user.email "your_email_address@example.com" +
-git config --global --list+
  
 +Ressources : 
 +
 +  * https://tedomum.net/training/git/
 +  * https://forge.tedomum.net/help/topics/git/commands.md
 +  * https://git-scm.com/book/fr/v2
 +  * https://about.gitlab.com/images/press/git-cheat-sheet.pdf
 +
 +===== Connexion en SSH sous Windows =====
 +Tout est volé ici : https://www.it-connect.fr/comment-generer-une-paire-de-cles-ssh-et-lutiliser-avec-gitlab/
 +
 +J'utilise le GitLab de Tedomum avec une authentification SSH. L'authentification par token HTTPS est aussi disponible mais je n'ai vu ça qu'après. OpenSSH est intégré sous Windows 10 et 11.
 +
 +Générer une clef : 
 +<code bash>
 +ssh-keygen -t ed25519
 +Enter file in which to save the key (C:\Users\utilisateur/.ssh/id_ed25519): C:\Users\utilisateur\.ssh\gittedo
 +Enter passphrase (empty for no passphrase):
 +Enter same passphrase again:
 +Your identification has been saved in C:\Users\utilisateur\.ssh\gittedo
 +Your public key has been saved in C:\Users\utilisateur\.ssh\gittedo.pub
 +The key fingerprint is:
 +SHA256:
 +The key's randomart image is:
 ++--[ED25519 256]--+
 +|  ..E  .o++.  o .|
 +| . .. . oo+= o B |
 +|  .  .   o+.B *.=|
 +|       o +.B + =o|
 +|        S B . . .|
 +|       + + = . . |
 +|        + + . o  |
 +|       . . o o   |
 +|            . .  |
 ++----[SHA256]-----+
 </code> </code>
  
-===== Initialiser et ajouter un dépôt ===== +On met la clef dans le presse papier :  
-<code shell+<code powershell> 
-cd dossier_repo+cat C:\Users\utilisateur\.ssh\gittedo.pub | clip 
 +</code> 
 + 
 +Ajouter la clef privée :  
 +<code powershell> 
 +ssh-add C:\Users\utilisateur\.ssh\gittedo 
 +</code> 
 + 
 +Si d'aventure ''ssh-add'' ne fonctionne pas, vérifier si le service est bien lancé soit par ''services.msc'' soit avec les commandes suivantes (voir [[https://stackoverflow.com/questions/65741816/error-connecting-to-agent-no-such-file-or-directory-adding-key-to-ssh-agent|ce fil sur Stackoverflow]]). Par défaut le service n'est pas lancé :  
 +<code powershell> 
 +# Active le service 
 +Get-Service ssh-agent | Set-Service -StartupType Automatic 
 +# Démarre le service 
 +Start-Service ssh-agent 
 +# Vérifie que le service est lancé 
 +Get-Service ssh-agent 
 +</code> 
 + 
 +Sur GitLab, aller dans Preferences > SSH Keys > Add new key et coller la clef dans le champ ''Key''
 + 
 +Tenter la connexion :  
 + 
 +<code bash> 
 +ssh -T git@forge.tedomum.net 
 +Welcome to GitLab, @yahiko! 
 +</code> 
 + 
 +Pour que cela fonctionne avec git, il faut aussi indiquer à git la clef privée :  
 +<code bash> 
 +git config --global core.sshCommand "ssh -i C:/users/utilisateur/.ssh/gittedo" 
 +</code> 
 + 
 +===== Initialiser un projet ===== 
 +<code bash> 
 +git config --global user.name "Username" 
 +git config --global user.email mail@domaine.tld 
 +cd dossier_du_projet
 git init git init
-git remote add origin https://forge.tedomum.net/git-username/git-repo.git+git remote add origin git@forge.tedomum.net:utilisateur/projet.git 
 +</code> 
 + 
 +On vérifie 
 +<code bash>
 git remote -v git remote -v
 +</code>
 +
 +On change la branche
 +<code bash>
 git branch -M main git branch -M main
-git push -uf origin main 
 </code> </code>
  
-===== Ajouter des trucs au dépot ===== +===== Ajouter les fichiers au dépot ===== 
-<code shell+<code bash
-cd dossier_repo+cd dossier_du_projet
 git add [dossier ou fichier] git add [dossier ou fichier]
 git commit -m "Commentaire" git commit -m "Commentaire"
 git push git push
 +</code>
 +
 +Pour le premier envoi j'ai fait : 
 +<code bash>
 +git add .
 +git commit -m "Version initiale"
 +git push --set-upstream origin main
 +</code>
 +
 +Lors du premier envoi : 
 +<code bash>
 +git push --set-upstream git@forge.tedomum.net:utilisateur/projet.git main
 +</code>
 +
 +Si problème lors du push : 
 +<code bash>
 +git pull --rebase origin main
 +git push --set-upstream origin main
 +</code>
 +
 +{{ :informatique:dog-sweat.gif?nolink |}}
 +
 +===== Git pull =====
 +
 +Pour récupérer le projet sur un autre machine 
 +
 +<code bash>
 +mkdir dossier && cd dossier
 +git init
 +git pull git@forge.tedomum.net:utilisateur/projet.git
 </code> </code>
informatique/git.1731953288.txt.gz · Last modified: 2024/11/18 18:08 by yahiko