Afficher la pageAnciennes révisionsLiens de retourAjouter au livre.Haut de page Cette page est en lecture seule. Vous pouvez afficher le texte source, mais ne pourrez pas le modifier. Contactez votre administrateur si vous pensez qu'il s'agit d'une erreur. ====== GIT (GitHub / GitLab / Gitea) ====== ===== Installation ===== Installer Oh-My-Bash à l’aide de curl bash -c "$(curl -fsSL https://raw.githubusercontent.com/ohmybash/oh-my-bash/master/tools/install.sh)" Après l’installation : source ~/.bashrc Modifier thème de Bash dans ~/.bashrc \\ [[https://github.com/ohmybash/oh-my-bash/wiki/Themes]] \\ nano ~/.bashrc Modifier la ligne OSH_THEME="font" en OSH_THEME="absimple" Recharger le .bashrc source ~/.bashrc \\ \\ ===== Utilisation ===== ==== Configurer GIT ==== === Configurer un projet GIT === # configuration locale d'un projet git config user.name Matt git config user.email matt@monentreprise.net # configuration globale de git $ git config --global user.name Matt $ git config --global user.email matt@monentreprise.net # lire la configuration actuelle git config --list # Pour facilité la vision des logs git config --global pager.log false ==== Commandes GIT ==== === Installer git === dnf install git # redhat/oracle os apt install git # debian os === Voir la version git === git --version === Aide git === git --help man git man git [cmd] === Clonage depot git === git clone http://url/du/projet === Initialiser un projet git === mkdir monprojet git init monprojet === Voir le statut du projet git === git status === Ajouter un fichier/dossier au projet git === git add mondossier git add monfichier git add . === Versionner un dossier avec message === git commit git commit -m "message" === Voir les logs === git log git log --oneline git log --oneline --name-status ==== Procedure Git classique ==== === Initier un projet git === mkdir mon projet cd monprojet/ git init touch README.md git add . git commit -m "Init new project" git push origin master === Démarrer un projet depuis un depot git === git clone http://url/monprojet.git cd monprojet ==== Git BRANCH ==== === Créér une branche === git branch develop === Supprimer une branche === git branch -d nom-de-branche === Changer de branche === git checkout develop === Créér et changer de branche === git checkout -b develop === Voir les branches === git branch === Fusionner deux branches === # se positionner sur la branche où il va y'avoir la fusion git checkout master # faire la fusion de la branch vers celle ou on est positionné git merge develop ==== Bonnes pratiques ==== Créér des sous branches dans develop, puis les fusionner dans develop, puis les fusionner dans master # depuis develop git checkout -b ansible touch test.yaml git add . git commit -m "add config" # revenir dans la branche supérieur (develop) git checkout develop git merge ansible # puis fusionner les divers changements dans master ==== Git TAG ==== Donner des numéros de versions à ses commits === Créér un tag === git tag v1.0 === Voir un tag === git tag git show v0.1 === Procedure pour créér un TAG sur un commit antérieur === # Regarder les logs git log --oneline # Tagger le hash du commit souhaité git tag v0.1 70ae760 # Vérifier le TAG git show v0.1 ==== SSH ==== === Création de la clé SSH === ssh-keygen -o -a 100 -t ed25519 -C "VM_TP4_Module9" === Création d'un alias SSH === $ vi ~/.ssh/config Host gitlab HostName gitlab.example.com User git Port 22 IdentityFile /home/elisa/.ssh/id_ed25519 Maintenant l'alias gitlab est créer ==== Vérifier type de connexion ==== Vérifier type connexion http ou ssh pour le push git remote -v ==== Git PUSH / PULL ==== La toute premiere fois pour la branche ou branche qui n'existe pas encore git push --set-upstream origin nom-de-branche Ensuite vous pouvez simplement utiliser git push Télécharger les modifications git pull nom-de-branche ==== Git ROLLBACK ==== === Rollback d'une modification non encore commitée === git checkout -- readme ==== Git RESET ==== La Commande GIT RESET (ne garde pas l'historique des commits, supprime le commit) === rollback au commit précédent en gardant les modifications de l'espace de travail === git reset --soft HEAD~1 === rollback au commit précédent sans garder les modifications de l'espace de travail === git reset --hard HEAD~1 ==== Git REVERT ==== === commande git revert (garde l'historique des commits,créé un nouveau commit en inversant les changements apportés par un commit) === git revert [hash commit1] [hash commit 2] ... \\ \\ ===== TP ===== Command line instructions You can also upload existing files from your computer using the instructions below. ==== Git global setup ==== git config --global user.name "user16-eni" git config --global user.email "user16-eni@eni.local" ==== Create a new repository ==== git clone git@gitasr.campus-eni.fr:user16-eni/user16-project.git cd user16-project git switch -c main touch README.md git add README.md git commit -m "add README" git push -u origin main Push an existing folder ==== cd existing_folder ==== git init --initial-branch=main git remote add origin git@gitasr.campus-eni.fr:user16-eni/user16-project.git git add . git commit -m "Initial commit" git push -u origin main ==== Push an existing Git repository ==== cd existing_repo git remote rename origin old-origin git remote add origin git@gitasr.campus-eni.fr:user16-eni/user16-project.git git push -u origin --all git push -u origin --tags ===== Sources : ===== https://git-scm.com/book/fr/v2/Utilitaires-Git-Reset-d%C3%A9mystifi%C3%A9 public/git.txt Dernière modification : 2024/10/24 11:30de 127.0.0.1