{"id":320,"date":"2017-03-03T09:22:38","date_gmt":"2017-03-03T08:22:38","guid":{"rendered":"http:\/\/union31xh.free.fr\/?p=320"},"modified":"2017-07-28T10:52:32","modified_gmt":"2017-07-28T08:52:32","slug":"git-commande-de-bases","status":"publish","type":"post","link":"https:\/\/blogperso.union31.fr\/?p=320","title":{"rendered":"GIT : commandes de base"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Sommaire<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blogperso.union31.fr\/?p=320\/#I_Introduction\" >I Introduction<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blogperso.union31.fr\/?p=320\/#I1_Resume\" >I.1 R\u00e9sum\u00e9<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blogperso.union31.fr\/?p=320\/#I2_Principe\" >I.2 Principe<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blogperso.union31.fr\/?p=320\/#II_Commandes_de_bases\" >II Commandes de bases<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blogperso.union31.fr\/?p=320\/#II1_Aide\" >II.1 Aide<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blogperso.union31.fr\/?p=320\/#II2_Gestion_courante\" >II.2 Gestion courante<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blogperso.union31.fr\/?p=320\/#II3_Operations_avec_serveur_distant\" >II.3 Op\u00e9rations avec serveur distant<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/blogperso.union31.fr\/?p=320\/#II31_Operations_courantes\" >II.3.1 Op\u00e9rations courantes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/blogperso.union31.fr\/?p=320\/#II32_Operations_particulieres\" >II.3.2 Op\u00e9rations particuli\u00e8res<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/blogperso.union31.fr\/?p=320\/#II4_gestion_des_branches\" >II.4 gestion des branches<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/blogperso.union31.fr\/?p=320\/#III_Autres\" >III Autres<\/a><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"I_Introduction\"><\/span>I Introduction<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<h2><span class=\"ez-toc-section\" id=\"I1_Resume\"><\/span>I.1 R\u00e9sum\u00e9<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>C&rsquo;est un outil de versioning de code suivant un mod\u00e8le distribu\u00e9.<\/p>\n<p>Lien site officiel : <a href=\"https:\/\/git-scm.com\/\" target=\"_blank\">https:\/\/git-scm.com\/<\/a><\/p>\n<h2><span class=\"ez-toc-section\" id=\"I2_Principe\"><\/span>I.2 Principe<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>T\u00e9l\u00e9charger le client GIT \u00e0 partir du site officiel.<\/p>\n<p>Ex\u00e9cuter l&rsquo;installateur (windows) puis suivant suivant &#8230;<\/p>\n<p>Lancer \u00ab\u00a0Git-Bash\u00a0\u00bb. Une console appara\u00eet (cygwin).<\/p>\n<p>Aller dans le r\u00e9pertoire racine du projet en cours de d\u00e9veloppement. C&rsquo;est parti !!!<\/p>\n<h1><span class=\"ez-toc-section\" id=\"II_Commandes_de_bases\"><\/span>II Commandes de bases<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<h2><span class=\"ez-toc-section\" id=\"II1_Aide\"><\/span>II.1 Aide<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Obtenir de l&rsquo;aide sur une commande git<\/p>\n<pre>git help commande<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"II2_Gestion_courante\"><\/span>II.2 Gestion courante<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Premi\u00e8re installation : initialiser son profil<\/p>\n<pre>git config --global user.name \"pseudo\"\r\ngit config --global user.email \"adresse@mail.fr\"<\/pre>\n<p>&nbsp;<\/p>\n<p>Initialisation d&rsquo;un repository local<\/p>\n<pre>git init<\/pre>\n<p>Prise en compte de nouveaux fichiers<\/p>\n<pre>git add nom_de_fichier \/\/ prise en compte d'un fichier\r\ngit add .              \/\/ prise en compte de tous les fichiers (et r\u00e9pertoires)<\/pre>\n<p>Valider une version<\/p>\n<pre>git commit -m \"commentaire\"      \/\/ valide une version\r\ngit commit -a -m \"commentaire\"   \/\/ prise en compte des fichiers modifi\u00e9s + commit<\/pre>\n<p>Affiche les diff\u00e9rents commit du repository<\/p>\n<pre>git log<\/pre>\n<p>Se positionner sur une ancienne version<\/p>\n<pre>git checkout SHAcommit<\/pre>\n<p>Revenir \u00e0 la version principale<\/p>\n<pre>git checkout master<\/pre>\n<p>Supprimer un commit<\/p>\n<pre>git revert SHACommit<\/pre>\n<p>Modifier le commentaire d&rsquo;un commit<\/p>\n<pre>git commit --amend -m \"commentaire\"<\/pre>\n<p>Qui a modifi\u00e9 un fichier particulier<\/p>\n<pre>git blame nom_fichier<\/pre>\n<p>D\u00e9tail de la modification pour un fichier<\/p>\n<pre>git show debSHA<\/pre>\n<p>&nbsp;<\/p>\n<h2><span class=\"ez-toc-section\" id=\"II3_Operations_avec_serveur_distant\"><\/span>II.3 Op\u00e9rations avec serveur distant<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"II31_Operations_courantes\"><\/span>II.3.1 Op\u00e9rations courantes<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Clone d&rsquo;un repository git<\/p>\n<pre>git clone url_http<\/pre>\n<p>Envoyer le repository local sur un serveur distant<\/p>\n<pre>git push origin master    \/\/ pousse la branche master<\/pre>\n<p>R\u00e9cup\u00e9rer le repository distant vers le local<\/p>\n<pre>git pull origin master<\/pre>\n<p>Visionner les serveurs distants<\/p>\n<pre>git remote\r\ngit remote -v<\/pre>\n<p>Ajouter un d\u00e9pot existant<\/p>\n<pre>git remote add nom @url_depot    \/\/ nom --&gt; origin par exemple<\/pre>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"II32_Operations_particulieres\"><\/span>II.3.2 Op\u00e9rations particuli\u00e8res<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Si la version sur le serveur a \u00e9t\u00e9 modifi\u00e9e soit directement sur ce dernier ou par un autre utilisateur, il n&rsquo;est plus possible de pousser ses modifications.<\/p>\n<p>Un message suivant appara\u00eet :<\/p>\n<pre>hint: Updates were rejected because the remote contains work that you do\r\nhint: not have locally. This is usually caused by another repository pushing\r\nhint: to the same ref. You may want to first integrate the remote changes\r\nhint: (e.g., 'git pull ...') before pushing again.\r\nhint: See the 'Note about fast-forwards' in 'git push --help' for details.<\/pre>\n<p>Il faut r\u00e9cup\u00e9rer les modifications sur son d\u00e9p\u00f4t puis ensuite pousser ses modifications :<\/p>\n<pre>git fetch origin\r\ngit merge origin\/master\r\ngit push origin master<\/pre>\n<p>Une explication d\u00e9taill\u00e9e et simple \u00e0 comprendre : <a href=\"https:\/\/git-scm.com\/book\/fr\/v1\/Git-distribu%C3%A9-Contribution-%C3%A0-un-projet\" target=\"_blank\">ici<\/a><\/p>\n<p>&nbsp;<\/p>\n<h2><span class=\"ez-toc-section\" id=\"II4_gestion_des_branches\"><\/span>II.4 gestion des branches<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>visualiser les branches d&rsquo;un repository<\/p>\n<pre>git branch\r\ngit branch -v<\/pre>\n<p>Cr\u00e9er une nouvelle branche<\/p>\n<pre>git branch nouvelle_branche<\/pre>\n<p>Supprime une branche<\/p>\n<pre>git branch -D nom_branch<\/pre>\n<p>Se positionner sur une branche<\/p>\n<pre>git checkout nom_branche\r\ngit checkout -b nom_branche  \/\/ cr\u00e9ation et positionnement sur une nouvelle branche<\/pre>\n<p>Fusionner une branche<\/p>\n<pre>git merge branch nom_branche<\/pre>\n<p>&nbsp;<\/p>\n<h1><span class=\"ez-toc-section\" id=\"III_Autres\"><\/span>III Autres<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>Ignore la prise en compte des fichiers<\/p>\n<p>fichier \u00e0 la racine \u00ab\u00a0.gitignore\u00a0\u00bb dans lequel on met des repertoires ou noms de fichiers pr\u00e9cis<\/p>\n<p>Autres commandes \u00e0 explorer :<\/p>\n<pre>git stash          \/\/ mettre de c\u00f4t\u00e9 les modifications en cours\r\ngit stash po       \/\/ reprendre ...\r\ngit stash apply<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I Introduction I.1 R\u00e9sum\u00e9 C&rsquo;est un outil de versioning de code suivant un mod\u00e8le distribu\u00e9. Lien site officiel : https:\/\/git-scm.com\/ I.2 Principe T\u00e9l\u00e9charger le client GIT \u00e0 partir du site officiel. Ex\u00e9cuter l&rsquo;installateur (windows) puis suivant suivant &#8230; Lancer \u00ab\u00a0Git-Bash\u00a0\u00bb.<\/p>\n","protected":false},"author":1,"featured_media":332,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-320","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-_dev"],"_links":{"self":[{"href":"https:\/\/blogperso.union31.fr\/index.php?rest_route=\/wp\/v2\/posts\/320","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogperso.union31.fr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogperso.union31.fr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogperso.union31.fr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogperso.union31.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=320"}],"version-history":[{"count":26,"href":"https:\/\/blogperso.union31.fr\/index.php?rest_route=\/wp\/v2\/posts\/320\/revisions"}],"predecessor-version":[{"id":490,"href":"https:\/\/blogperso.union31.fr\/index.php?rest_route=\/wp\/v2\/posts\/320\/revisions\/490"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogperso.union31.fr\/index.php?rest_route=\/wp\/v2\/media\/332"}],"wp:attachment":[{"href":"https:\/\/blogperso.union31.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=320"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogperso.union31.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=320"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogperso.union31.fr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=320"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}