{"id":117,"date":"2017-04-13T10:54:00","date_gmt":"2017-04-13T13:54:00","guid":{"rendered":"https:\/\/www.linuxpro.com.br\/2017\/04\/git-simples-e-rapido\/"},"modified":"2026-09-08T01:56:22","modified_gmt":"2026-09-08T04:56:22","slug":"git-simples-e-rapido","status":"publish","type":"post","link":"https:\/\/www.linuxpro.com.br\/es\/2017\/04\/git-simples-e-rapido\/","title":{"rendered":"Git simples e r\u00e1pido"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" alt=\"Mascote do LinuxPro diante de um quadro com o diagrama de branch e merge do Git, ao lado do losango do projeto\" src=\"\/wp-content\/uploads\/2026\/09\/git-v5.webp\" width=\"1052\" height=\"652\" \/><\/p>\n<div style=\"background:#fff8e1;border-left:4px solid #8b1a1a;padding:.8em 1em;margin:1em 0\"><strong>Nota (2026):<\/strong> o fluxo abaixo continua o do dia a dia. O pacote agora \u00e9 <code data-no-translation=\"\">git<\/code> (n\u00e3o <code data-no-translation=\"\">git-core<\/code>), o ramo padr\u00e3o costuma ser <code data-no-translation=\"\">main<\/code> e a chave SSH moderna \u00e9 Ed25519. A hist\u00f3ria \u2014 BitKeeper, os dez dias de 2005, Junio Hamano, Git 2.55 \u2014 est\u00e1 em <a href=\"\/es\/2026\/09\/a-historia-do-git\/\">A hist\u00f3ria do Git<\/a>.<\/div>\n<p>Cheatsheet curto: instalar, configurar, clonar, commitar, enviar. Sem teoria de objeto. Se voc\u00ea nunca usou Git, estes s\u00e3o os comandos que resolvem 90% dos casos.<\/p>\n<p><!-- more --><\/p>\n<h2>Instalar<\/h2>\n<p>Debian\/Ubuntu e derivados:<\/p>\n<pre data-no-translation=\"\"><code class=\"language-bash\" data-no-translation=\"\">sudo apt update\nsudo apt install git\ngit --version<\/code><\/pre>\n<p>Em 2026 o pacote \u00e9 <code data-no-translation=\"\">git<\/code>. O nome antigo <code data-no-translation=\"\">git-core<\/code> era um metapacote; n\u00e3o procure por ele.<\/p>\n<h2>Nome, e-mail e ramo padr\u00e3o<\/h2>\n<pre data-no-translation=\"\"><code class=\"language-bash\" data-no-translation=\"\">git config --global user.name \"Seu Nome\"\ngit config --global user.email seu@email.com\ngit config --global init.defaultBranch main\ngit config --global pull.rebase false<\/code><\/pre>\n<p><code data-no-translation=\"\">user.name<\/code> e <code data-no-translation=\"\">user.email<\/code> entram em todo commit. Sem isso o Git reclama. O ramo padr\u00e3o da ind\u00fastria deixou de ser <code data-no-translation=\"\">master<\/code> por volta de 2020; <code data-no-translation=\"\">main<\/code> \u00e9 o que GitHub, GitLab e o pr\u00f3prio Git usam em reposit\u00f3rio novo.<\/p>\n<h2>Chave SSH<\/h2>\n<p>Ed25519, n\u00e3o RSA 4096 \u2014 menor e o default atual. Detalhe do fluxo sem senha: <a href=\"\/es\/2017\/04\/ssh-sem-senha\/\">SSH sem senha<\/a>.<\/p>\n<pre data-no-translation=\"\"><code class=\"language-bash\" data-no-translation=\"\">ssh-keygen -t ed25519 -C \"seu@email.com\"\neval \"$(ssh-agent -s)\"\nssh-add ~\/.ssh\/id_ed25519\ncat ~\/.ssh\/id_ed25519.pub<\/code><\/pre>\n<p>Cole a chave p\u00fablica em GitHub\/GitLab \u2192 Settings \u2192 SSH keys. Teste:<\/p>\n<pre data-no-translation=\"\"><code class=\"language-bash\" data-no-translation=\"\">ssh -T git@github.com<\/code><\/pre>\n<h2>Reposit\u00f3rio novo ou clone<\/h2>\n<pre data-no-translation=\"\"><code class=\"language-bash\" data-no-translation=\"\">mkdir projeto && cd projeto\ngit init\n# ou, o caso comum:\ngit clone git@github.com:usuario\/projeto.git\ncd projeto<\/code><\/pre>\n<h2>Add, commit, status<\/h2>\n<pre data-no-translation=\"\"><code class=\"language-bash\" data-no-translation=\"\">git status\ngit add arquivo.txt          # ou: git add -A\ngit commit -m \"mensagem curta no imperativo\"\ngit log --oneline -5<\/code><\/pre>\n<p class=\"translation-block\">O commit fica no reposit\u00f3rio <em>local<\/em>. Ainda n\u00e3o est\u00e1 no GitHub.<\/p>\n<h2>Branch: switch, n\u00e3o s\u00f3 checkout<\/h2>\n<pre data-no-translation=\"\"><code class=\"language-bash\" data-no-translation=\"\">git switch -c feature\/login    # cria e entra\ngit switch main                # volta\ngit merge feature\/login\ngit branch -d feature\/login<\/code><\/pre>\n<p><code data-no-translation=\"\">git switch<\/code> e <code data-no-translation=\"\">git restore<\/code> (desfazer arquivo) existem desde o Git 2.23 (2019) e separam o que o <code data-no-translation=\"\">checkout<\/code> fazia demais. <code data-no-translation=\"\">checkout<\/code> ainda funciona; para c\u00f3digo novo, use os dois novos.<\/p>\n<pre data-no-translation=\"\"><code class=\"language-bash\" data-no-translation=\"\">git restore arquivo.txt           # descarta mudan\u00e7a no working tree\ngit restore --staged arquivo.txt  # tira do index, mant\u00e9m o arquivo<\/code><\/pre>\n<h2>Remote e push<\/h2>\n<pre data-no-translation=\"\"><code class=\"language-bash\" data-no-translation=\"\">git remote add origin git@github.com:usuario\/projeto.git\ngit push -u origin main<\/code><\/pre>\n<p>Nas pr\u00f3ximas vezes: <code data-no-translation=\"\">git push<\/code> e <code data-no-translation=\"\">git pull<\/code>. O <code data-no-translation=\"\">-u<\/code> grava o upstream. Se o remoto ainda usa <code data-no-translation=\"\">master<\/code>, troque o nome do ramo \u2014 n\u00e3o invente <code data-no-translation=\"\">main<\/code> num remoto que n\u00e3o tem.<\/p>\n<pre data-no-translation=\"\"><code class=\"language-bash\" data-no-translation=\"\">git branch -M main    # s\u00f3 se voc\u00ea est\u00e1 migrando um repo antigo<\/code><\/pre>\n<h2>O fluxo de um dia<\/h2>\n<pre data-no-translation=\"\"><code class=\"language-bash\" data-no-translation=\"\">git pull\ngit switch -c fix\/typo\n# edita\ngit add -A\ngit commit -m \"Corrige typo no README\"\ngit push -u origin fix\/typo\n# abre o pull request no GitHub\/GitLab\ngit switch main<\/code><\/pre>\n<h2>V\u00eddeo: Descomplicando o Git (LinuxTips)<\/h2>\n<p class=\"translation-block\">O <a href=\"https:\/\/www.youtube.com\/channel\/UCJnKVGmXRXrH49Tvrx5X0Sw\">LinuxTips<\/a> do Jeferson Fernando gravou o \u201cDescomplicando o GIT\u201d \u2014 ainda o melhor passeio em portugu\u00eas pelo fluxo. A hist\u00f3ria (BitKeeper, os dez dias, o Git 2.55) ficou no post novo.<\/p>\n<div style=\"position:relative;padding-bottom:56.25%;height:0;overflow:hidden;margin:1.5em 0\">\n<iframe src=\"https:\/\/www.youtube.com\/embed\/_aj3hsEh9iw\" title=\"Descomplicando o GIT \u2014 LinuxTips\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen style=\"position:absolute;top:0;left:0;width:100%;height:100%;border:0\"><\/iframe>\n<\/div>\n<h2>Mais<\/h2>\n<ul>\n<li><a href=\"\/es\/2026\/09\/a-historia-do-git\/\">A hist\u00f3ria do Git<\/a> \u2014 BitKeeper, Linus, Junio, 2.55<\/li>\n<li><a href=\"\/es\/2026\/09\/a-historia-de-linus-torvalds\/\">A hist\u00f3ria de Linus Torvalds<\/a><\/li>\n<li><a href=\"https:\/\/git-scm.com\/book\/pt-br\/v2\">Pro Git (livro oficial, v2 em portugu\u00eas)<\/a><\/li>\n<li><a href=\"https:\/\/www.youtube.com\/watch?v=sCr_gb8rdEI\">Two decades of Git \u2014 entrevista com Linus (2025)<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Cheatsheet curto: instalar, configurar, clonar, commitar, enviar. Sem teoria de objeto. Se voc\u00ea nunca usou Git, estes s\u00e3o os comandos que resolvem 90% dos casos. Instalar Debian\/Ubuntu e derivados: sudo apt update sudo apt install git git &#8211;version Em 2026 &#8230; <a title=\"Git simples e r\u00e1pido\" class=\"read-more\" href=\"https:\/\/www.linuxpro.com.br\/es\/2017\/04\/git-simples-e-rapido\/\" aria-label=\"Read more about Git simples e r\u00e1pido\">Read more<\/a><\/p>","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[45,46,2],"tags":[50,47,48,49,4,51],"class_list":["post-117","post","type-post","status-publish","format-standard","hentry","category-desenv","category-devops","category-linux","tag-desenv","tag-devops","tag-git","tag-github","tag-linux","tag-win"],"_links":{"self":[{"href":"https:\/\/www.linuxpro.com.br\/es\/wp-json\/wp\/v2\/posts\/117","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.linuxpro.com.br\/es\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linuxpro.com.br\/es\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linuxpro.com.br\/es\/wp-json\/wp\/v2\/comments?post=117"}],"version-history":[{"count":8,"href":"https:\/\/www.linuxpro.com.br\/es\/wp-json\/wp\/v2\/posts\/117\/revisions"}],"predecessor-version":[{"id":1061,"href":"https:\/\/www.linuxpro.com.br\/es\/wp-json\/wp\/v2\/posts\/117\/revisions\/1061"}],"wp:attachment":[{"href":"https:\/\/www.linuxpro.com.br\/es\/wp-json\/wp\/v2\/media?parent=117"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linuxpro.com.br\/es\/wp-json\/wp\/v2\/categories?post=117"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linuxpro.com.br\/es\/wp-json\/wp\/v2\/tags?post=117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}