<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Renato Teixeira</title>
    <description>The latest articles on Forem by Renato Teixeira (@reenatoteixeira).</description>
    <link>https://forem.com/reenatoteixeira</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1257274%2F12a280c7-7a40-4ddc-8e04-bb692e0ce473.png</url>
      <title>Forem: Renato Teixeira</title>
      <link>https://forem.com/reenatoteixeira</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/reenatoteixeira"/>
    <language>en</language>
    <item>
      <title>Tudo o que você precisa saber sobre GIT</title>
      <dc:creator>Renato Teixeira</dc:creator>
      <pubDate>Mon, 12 Feb 2024 14:30:00 +0000</pubDate>
      <link>https://forem.com/reenatoteixeira/tudo-o-que-voce-precisa-saber-sobre-git-53c1</link>
      <guid>https://forem.com/reenatoteixeira/tudo-o-que-voce-precisa-saber-sobre-git-53c1</guid>
      <description>&lt;p&gt;Certamente você pode imaginar a importância de se versionar um código, para poder &lt;strong&gt;reverter alterações&lt;/strong&gt;, &lt;strong&gt;recuperar dados perdidos&lt;/strong&gt;, &lt;strong&gt;entre outras possibilidades&lt;/strong&gt;. E aposto que você conhece alguém &lt;em&gt;(não eu hehe)&lt;/em&gt; que controla a versão dos seus arquivos criando cópias deles com nomes cada vez mais criativos...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkx97mjx9jesulods13se.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkx97mjx9jesulods13se.gif" alt="GIF simulando a duplicação de um arquivo com nomes direfentes. Exemplo: tcc, tcc-versãoFinal, etc." width="610" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Até 1972, provavelmente era assim que qualquer pessoa faria o controle de versão dos seus códigos também, antes do lançamento do &lt;strong&gt;SCCS &lt;em&gt;(Source Code Control System)&lt;/em&gt;&lt;/strong&gt;, um dos primeiros softwares de gerenciamento de versões &lt;strong&gt;centralizados&lt;/strong&gt; que já foram lançados.&lt;/p&gt;

&lt;p&gt;Mas não é o SCCS que nos interessa agora e sim o &lt;strong&gt;GIT&lt;/strong&gt;, software de versionamento de código &lt;strong&gt;distribuído&lt;/strong&gt; open-source que completa 20 anos do seu lançamento no ano que vem &lt;em&gt;(07/04/2005)&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Índice
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;1. O que é GIT?&lt;/li&gt;
&lt;li&gt;2. Como o GIT funciona?&lt;/li&gt;
&lt;li&gt;3. Instalando o GIT&lt;/li&gt;
&lt;li&gt;4. Configurando o GIT&lt;/li&gt;
&lt;li&gt;5. Iniciando um repositório local&lt;/li&gt;
&lt;li&gt;6. Trabalhando com GIT&lt;/li&gt;
&lt;li&gt;7. Conhecendo as branches&lt;/li&gt;
&lt;li&gt;8. Sincronizando com o repositório remoto&lt;/li&gt;
&lt;li&gt;9. Conclusão&lt;/li&gt;
&lt;li&gt;10. Referências&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  1. O que é GIT? &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;GIT é um sistema de controle de versão &lt;strong&gt;distribuído&lt;/strong&gt; open-source lançado em 2005, que foi desenvolvido por Linus Torvald &lt;em&gt;(isso mesmo, o criador do kernel do Linux)&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Com o GIT, é possível &lt;strong&gt;controlar as versões de um projeto&lt;/strong&gt; localmente &lt;em&gt;(na pasta de trabalho)&lt;/em&gt; e sincronizar todas as alterações para um repositório remoto &lt;em&gt;(no GitHub, por exemplo)&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Como o GIT funciona? &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Imagine um arquivo &lt;strong&gt;físico&lt;/strong&gt; onde há uma pasta com todos os arquivos do projeto. Dessa forma, sempre que alguém precisar manipular um arquivo, é preciso pegá-lo, &lt;strong&gt;removendo-o de dentro da pasta e retornando-o para a pasta após concluir o trabalho&lt;/strong&gt;. Assim, é &lt;strong&gt;impossível&lt;/strong&gt; que duas pessoas trabalhem num mesmo arquivo, evitando totalmente possíveis conflitos.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MAS NÃO É ASSIM QUE O GIT FUNCIONA!&lt;/strong&gt; &lt;em&gt;(ainda bem)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Esse é o funcionamento de um sistema de versionamento &lt;strong&gt;CENTRALIZADO&lt;/strong&gt;, no qual o usuário precisa realizar o &lt;strong&gt;"check-out"&lt;/strong&gt; e &lt;strong&gt;"check-in"&lt;/strong&gt; de arquivos, ou seja, sempre que alguém precisa trabalhar em um determinado arquivo é necessário realizar o "check-out" desse arquivo, &lt;strong&gt;removendo-o do repositório&lt;/strong&gt;, e depois de concluído o trabalho, realizar o "check-in" do arquivo, &lt;strong&gt;retornando-o para o repositório&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvlwj7qzpzeyesqcg8pup.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvlwj7qzpzeyesqcg8pup.gif" alt="GIF simulando o funcionamento de um sistema de controle de versão centralizado." width="610" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Em um sistema &lt;strong&gt;DISTRIBUÍDO&lt;/strong&gt; como o &lt;strong&gt;GIT&lt;/strong&gt;, é possível que várias pessoas acessem arquivos de um mesmo repositório remoto. Dessa forma, sempre que alguém precisar manipular um arquivo, basta &lt;strong&gt;cloná-lo&lt;/strong&gt; &lt;em&gt;(ou clonar todo o repositório)&lt;/em&gt; localmente para sua máquina, e depois enviar as modificações de volta ao repositório remoto. Assim, é possível que &lt;strong&gt;diversas pessoas trabalhem no mesmo projeto&lt;/strong&gt;, manipulando até mesmo os &lt;strong&gt;mesmos arquivos&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvxafv9z26zpc2y4w4z8d.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvxafv9z26zpc2y4w4z8d.gif" alt="GIF simulando o funcionamento de um sistema de controle de versão distribuído." width="610" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Esse tipo de abordagem é o que permite a distribuição de grandes projetos &lt;strong&gt;open-source&lt;/strong&gt;, com pessoas de diversas partes do mundo trabalhando em um mesmo projeto, gerenciando as modificações e possíveis conflitos &lt;em&gt;(sim, conflitos de merge podem acontecer aqui)&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Instalando o GIT &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Atualmente, &lt;strong&gt;GIT&lt;/strong&gt; está disponível para os principais sistemas operacionais &lt;em&gt;(Windows, Linux, MacOs...)&lt;/em&gt; e a sua instalação é bem simples, podendo ser feita por &lt;strong&gt;linha de comando&lt;/strong&gt; ou através do &lt;strong&gt;instalador oficial&lt;/strong&gt; em &lt;a href="https://git-scm.com/" rel="noopener noreferrer"&gt;git-scm.com&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  3.1 No Windows
&lt;/h3&gt;

&lt;p&gt;Para instalar o GIT no Windows, basta acessar o site oficial e realizar o &lt;a href="https://git-scm.com/download/win" rel="noopener noreferrer"&gt;download do instalador&lt;/a&gt;.&lt;br&gt;
Com isso, basta apertar &lt;strong&gt;seguir as instruções&lt;/strong&gt; que tudo deve correr bem e será possível utilizar os comandos do GIT no seu terminal.&lt;/p&gt;
&lt;h3&gt;
  
  
  3.2 No Linux
&lt;/h3&gt;

&lt;p&gt;Para o Linux, é possível instalar o &lt;strong&gt;GIT&lt;/strong&gt; utilizando o &lt;strong&gt;comando&lt;/strong&gt; abaixo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;git-all
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Dessa forma, o &lt;strong&gt;GIT&lt;/strong&gt; estará pronto para ser usado em seu terminal.&lt;/p&gt;

&lt;h3&gt;
  
  
  3.3 No MacOS
&lt;/h3&gt;

&lt;p&gt;No Mac, a forma mais fácil de instalar o &lt;strong&gt;GIT&lt;/strong&gt; é instalando o &lt;a href="https://brew.sh/" rel="noopener noreferrer"&gt;Homebrew&lt;/a&gt; e então executando o &lt;strong&gt;comando&lt;/strong&gt; abaixo no terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;brew &lt;span class="nb"&gt;install &lt;/span&gt;git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Assim, o GIT também ficará disponível para ser utilizado em seu terminal.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Configurando o GIT &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Após a instalação, é importante &lt;strong&gt;configurar&lt;/strong&gt; o &lt;strong&gt;GIT&lt;/strong&gt; utilizando os comandos abaixo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; user.name &lt;span class="s2"&gt;"[username]"&lt;/span&gt;
&lt;span class="c"&gt;# ex.: John Doe&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; user. email &lt;span class="s2"&gt;"[email@email.com]"&lt;/span&gt;
&lt;span class="c"&gt;# ex.: johndoe@email.com&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Também é possível configurar usuários específicos para determinados repositórios locais removendo a tag &lt;code&gt;--global&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  5. Iniciando um repositório local &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Com o &lt;strong&gt;GIT&lt;/strong&gt; configurado, podemos &lt;strong&gt;iniciar nosso repositório&lt;/strong&gt;.&lt;br&gt;
Para isso, é possível &lt;strong&gt;iniciar um novo repositório do zero ou clonar um repositório remoto existente&lt;/strong&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  5.1 Iniciando do zero (git init)
&lt;/h3&gt;

&lt;p&gt;Para iniciar um novo repositório, basta navegar até a &lt;strong&gt;pasta raiz&lt;/strong&gt; que desejamos tornar um repositório e executar o comando abaixo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs0gk4uti8v71sprgiwx3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs0gk4uti8v71sprgiwx3.png" alt="Captura de tela de um terminal Linux executando o comando " width="771" height="80"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Dessa forma, um diretório &lt;code&gt;.git&lt;/code&gt; será criado dentro da pasta do projeto, que será &lt;strong&gt;responsável pelo controle de versão&lt;/strong&gt; na pasta de trabalho desse repositório local.&lt;/p&gt;

&lt;h3&gt;
  
  
  5.2 Clonando um repositório (git clone)
&lt;/h3&gt;

&lt;p&gt;Clonar um repositório remoto existente é tão fácil quanto iniciar um novo repositório do zero. Para isso, basta utilizar o comando &lt;code&gt;git clone&lt;/code&gt; passando a &lt;strong&gt;URL do repositório&lt;/strong&gt; à ser clonado como parâmetro dentro da pasta em que deseja clonar o repositório:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone &lt;span class="o"&gt;[&lt;/span&gt;url-do-repositório-clonado]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgfc4nzs7t3fpruyqjf17.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgfc4nzs7t3fpruyqjf17.png" alt="Captura de tela de um terminal Linux executando o comando " width="800" height="170"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Dessa forma, todo o repositório sera &lt;strong&gt;clonado&lt;/strong&gt; para sua máquina local, sendo &lt;strong&gt;automaticamente atrelado ao repositório remoto de origem&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Em um repositório clonado não haverá necessidade de utilizar o comando &lt;code&gt;git remote&lt;/code&gt; no futuro.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  6. Trabalhando com GIT &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Tendo o repositório local inicializado, é possível trabalhar em nosso projeto utilizando o controle de versão do &lt;strong&gt;GIT&lt;/strong&gt; localmente.&lt;/p&gt;

&lt;p&gt;Dentro do nosso &lt;strong&gt;repositório local&lt;/strong&gt;, podemos criar os arquivos necessários para o nosso projeto, mas eles &lt;strong&gt;não serão sincronizados automaticamente pelo GIT&lt;/strong&gt;, para isso é necessário que informemos quando houver mudanças para serem versionadas.&lt;/p&gt;

&lt;p&gt;Assim, podemos &lt;strong&gt;manipular&lt;/strong&gt; os arquivos como quisermos e, &lt;strong&gt;após concluir as alterações&lt;/strong&gt; desejadas, &lt;strong&gt;enviar os arquivos atualizados para o GIT&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Para isso, é importante entender que existe um &lt;strong&gt;fluxo infinito&lt;/strong&gt; (sim, infinito) de &lt;strong&gt;3 estágios&lt;/strong&gt; no controle de versões:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                    MODIFY -&amp;gt; STAGE -&amp;gt; COMMIT
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;MODIFY:&lt;/strong&gt; Primeiro estágio do controle de versões, aqui são colocados os &lt;strong&gt;arquivos que sofreram alguma alteração&lt;/strong&gt; comparada à última versão disponível.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;STAGE:&lt;/strong&gt; Segundo estágio do controle de versões, aqui são colocados os &lt;strong&gt;arquivos modificados que queremos adicionar&lt;/strong&gt; ao próximo commit.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;COMMIT:&lt;/strong&gt; Estágio final do controle de versões, quando &lt;strong&gt;confirmamos as modificações feitas&lt;/strong&gt;, enviando os arquivos modificados que estavam em stage para o repositório local.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Com os arquivos commitados, temos uma &lt;strong&gt;nova versão&lt;/strong&gt; disponível no repositório local, que pode novamente sofrer alterações, passando novamente para &lt;em&gt;"modified"&lt;/em&gt;, ter essas novas alterações colocadas em &lt;em&gt;"stage"&lt;/em&gt; e novamente &lt;em&gt;"commitadas"&lt;/em&gt;, confirmando uma nova versão e assim por diante &lt;em&gt;(e por isso "infinito" lol)&lt;/em&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Um commit não exclui a versão antiga dos arquivos modificados, apenas inclui a nova versão com um apontamento para a última versão disponível, mantendo assim o rastreamento das versões de cada arquivo rastreado pelo GIT.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  6.1 Adicionando e commitando (git add e git commit)
&lt;/h3&gt;

&lt;p&gt;Apesar de parecer complexo, executar o fluxo de versionamento é &lt;strong&gt;bem simples&lt;/strong&gt;. Após concluir as modificações desejadas, &lt;strong&gt;adicionamos os arquivos modificados que desejamos commitar em stage&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add &lt;span class="o"&gt;[&lt;/span&gt;nome-do-arquivo]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;git add -A&lt;/code&gt; -&amp;gt; adiciona todos os arquivos modificados para stage de uma vez.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git add *.[extensão-do-arquivo]&lt;/code&gt; -&amp;gt; adiciona todos os arquivos modificados com a extensão especificada para stage de uma vez (ex.: &lt;code&gt;git add *.html&lt;/code&gt;).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;É possível verificar o &lt;strong&gt;status&lt;/strong&gt; atual do nosso repositório a qualquer momento utilizando o comando &lt;code&gt;git status&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk5cbiaa1hfv6e9s0kdv0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk5cbiaa1hfv6e9s0kdv0.png" alt="Captura de tela de um terminal Linux executando o comando " width="799" height="259"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Perceba que, ao executar o &lt;code&gt;git status&lt;/code&gt; dentro do repositório &lt;strong&gt;após criar um novo arquivo&lt;/strong&gt;, o novo arquivo é exibido como &lt;em&gt;"Untracked"&lt;/em&gt;. Isso significa que esse arquivo é &lt;strong&gt;novo&lt;/strong&gt; e ainda precisa ser adicionado à algum commit para que seja &lt;strong&gt;rastreado&lt;/strong&gt; pelo &lt;strong&gt;GIT&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;É possível fazer com que o GIT ignore determinados arquivos ou pastas dentro do repositório. Para isso basta adicionar um arquivo à pasta raiz chamado &lt;code&gt;.gitignore&lt;/code&gt; e, dentro dele, destacar o nome dos arquivos ou pastas que devem ser ignorados.&lt;/p&gt;

&lt;p&gt;ATENÇÃO: Arquivos e pastas ignorados não aparecem mais no rastreamento do GIT, nem mesmo como "Untracked". Para retornar o rastreamento basta apagar os nomes do arquivo &lt;code&gt;.gitignore&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Para incluir um arquivo, podemos executar o comando &lt;code&gt;git add&lt;/code&gt; que vimos antes com o nome do arquivo que desejamos adicionar &lt;em&gt;("index.html" nesse caso)&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fefz8bakcop88psyhgd13.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fefz8bakcop88psyhgd13.png" alt="Captura de tela de um terminal Linux executando o comando " width="636" height="256"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Dessa forma, ao executar novamente o &lt;code&gt;git status&lt;/code&gt; podemos perceber que o novo arquivo foi adicionado ao &lt;em&gt;"stage"&lt;/em&gt; e está &lt;strong&gt;finalmente pronto para ser enviado no nosso próximo commit&lt;/strong&gt;, que pode ser feito utilizando o comando abaixo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"[mensagem-descritiva]"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;COMMITS possuem ID's (hash) únicos e são &lt;strong&gt;IMUTÁVEIS&lt;/strong&gt;, ou seja, não podem ser modificados após confirmados.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git commit -a&lt;/code&gt; -&amp;gt; realiza o commit direto, adicionando todos os arquivos modificados em stage e realizando o commit.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Após realizar o commit com sucesso&lt;/strong&gt;, ao executar o &lt;code&gt;git status&lt;/code&gt; percebemos que &lt;strong&gt;não há mais arquivos modificados para serem enviados&lt;/strong&gt;, uma vez que todas as modificações foram efetivamente salvas no nosso repositório local com o último &lt;strong&gt;commit&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl9rfaeoavyjjp31dlkkk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl9rfaeoavyjjp31dlkkk.png" alt="Captura de tela de um terminal Linux executando o comando " width="800" height="184"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ainda é possível &lt;strong&gt;comprovar as mudanças realizadas&lt;/strong&gt; ao rever o log de commits do repositório, utilizando o comando &lt;code&gt;git log&lt;/code&gt;, que mostra alguns metadados de todos os commits realizados como o código hash, branch, autor, data, etc.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3yb8uv7ur5g8c0w2pzgq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3yb8uv7ur5g8c0w2pzgq.png" alt="Captura de tela de um terminal Linux executando o comando " width="658" height="169"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Todo esse processo pode ser repetido para adicionar novos arquivos que sejam necessários ao seu projeto, modificá-los e enviá-los ao repositório local através de commits.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2uez3henix8kchperuw8.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2uez3henix8kchperuw8.gif" alt="GIF simulando a realização de diversos commits em uma branch do GIT." width="610" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;git log -N&lt;/code&gt; -&amp;gt; exibe o log dos últimos N commits.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git log [branch-A] [branch-B]&lt;/code&gt; -&amp;gt; exibe o log dos commits que estão na "branch-B" mas não estão na "branch-A".&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git log --follow [nome-do-arquivo]&lt;/code&gt; -&amp;gt; exibe o log dos commits que alteraram o arquivo especificado, mesmo que ele tenha mudado de nome.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git diff&lt;/code&gt; -&amp;gt; lista as modificações feitas em relação à última versão disponível no repositório.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git diff [nome-do-arquivo]&lt;/code&gt; -&amp;gt; lista as modificações feitas no arquivo especificado em relação à sua última versão disponível no repositório.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  6.2 Desfazendo mudanças antes e depois do commit
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Antes de realizar um commit&lt;/strong&gt;, todas as mudanças feitas no repositório local podem ser desfeitas, ou alteradas, mas &lt;strong&gt;após realizar o commit, não é possível alterá-lo&lt;/strong&gt;. Isso porque commits são &lt;strong&gt;objetos imutáveis&lt;/strong&gt;, ou seja, é impossível editar ou alterar as informações de um commit realizado.&lt;/p&gt;

&lt;p&gt;Ainda assim, &lt;strong&gt;é possível realizar novos commits&lt;/strong&gt; que desfazem alguma alteração, ou corrigem informações incorretas em commits anteriores. Para ambos os casos, podemos utilizar um dos comandos listados abaixo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;nome-do-arquivo]
&lt;span class="c"&gt;# Descarta as mudanças feitas no arquivo local, antes do commit (ação irreversível)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git reset &lt;span class="nt"&gt;--hard&lt;/span&gt; HEAD
&lt;span class="c"&gt;# Descarta as mudanças feitas em um arquivo que está em stage, antes do commit&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git reset &lt;span class="nt"&gt;--hard&lt;/span&gt; HEAD~1
&lt;span class="c"&gt;# Descarta o último commit realizado no repositório local (somente o último commit)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git commit &lt;span class="nt"&gt;--amend&lt;/span&gt;
&lt;span class="c"&gt;# Realiza um novo commit, substituindo o último commit feito no repositório local&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git revert &lt;span class="o"&gt;[&lt;/span&gt;hash-do-commit]
&lt;span class="c"&gt;# Realiza um novo commit revertendo as alterações do commit especificado&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  7. Conhecendo as branches &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Uma &lt;strong&gt;branch&lt;/strong&gt; nada mais é do que uma &lt;strong&gt;ramificação&lt;/strong&gt; do repositório e, até agora, todas as ações foram realizadas na branch &lt;code&gt;master/main&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Por padrão, a primeira branch criada no repositório é a branch &lt;code&gt;master/main&lt;/code&gt;, que é a branch principal do repositório.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  7.1 Pra que servem as branches?
&lt;/h3&gt;

&lt;p&gt;A princípio pode não parecer grande coisa, mas as &lt;strong&gt;branches dão um poder enorme pro desenvolvimento&lt;/strong&gt; do projeto.&lt;/p&gt;

&lt;p&gt;Imagine que estamos desenvolvendo uma plataforma web e queremos &lt;strong&gt;testar uma nova feature&lt;/strong&gt;, mas nosso repositório já está sendo &lt;strong&gt;hospedado ou compartilhado&lt;/strong&gt; com outras pessoas e qualquer alteração problemática pode causar uma péssima experiência à essas pessoas. O que podemos fazer?&lt;/p&gt;

&lt;p&gt;Se você pensou em &lt;strong&gt;duplicar&lt;/strong&gt; a pasta do projeto, criando uma &lt;strong&gt;"versão de testes"&lt;/strong&gt;, você acertou! Bom, em partes...&lt;/p&gt;

&lt;p&gt;Com o &lt;strong&gt;GIT&lt;/strong&gt;, é possível fazer algo parecido utilizando as &lt;strong&gt;branches&lt;/strong&gt;. Como elas são &lt;strong&gt;ramificações&lt;/strong&gt;, podemos simplesmente &lt;strong&gt;criar uma nova branch, chamada de "teste"&lt;/strong&gt; &lt;em&gt;(por exemplo)&lt;/em&gt;, e assim teremos uma versão do nosso projeto em uma branch totalmente &lt;strong&gt;isolada&lt;/strong&gt;, pronta pra ser revirada &lt;strong&gt;sem qualquer risco de impactar a branch principal&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffhasdypu3ey3dq056eca.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffhasdypu3ey3dq056eca.gif" alt="GIF simulando a criação de uma nova branch com novos commits sendo realizados nela." width="610" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  7.2 Criando branches (git branch)
&lt;/h3&gt;

&lt;p&gt;Criar uma &lt;strong&gt;branch&lt;/strong&gt; significa criar uma cópia paralela do repositório que pode ser trabalhada independentemente, sem impactar a branch &lt;code&gt;master/main&lt;/code&gt;. Para isso, basta utilizar o comando abaixo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git branch &lt;span class="o"&gt;[&lt;/span&gt;nome-da-branch]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Executar o comando &lt;code&gt;git branch&lt;/code&gt; sem um nome exibe a lista de branches disponíveis no repositório, com um "*" na branch que está sendo utilizada atualmente.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Antes de executar o comando &lt;code&gt;git branch teste&lt;/code&gt;, o comando &lt;code&gt;git branch&lt;/code&gt; retornava somente a branch &lt;code&gt;master&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzf4svh3t1bohyyy3jcvx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzf4svh3t1bohyyy3jcvx.png" alt="Captura de tela de um terminal Linux executando o comando " width="583" height="171"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Após criar uma nova branch, é possível alternar entre as branches disponíveis utilizando o comando abaixo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout &lt;span class="o"&gt;[&lt;/span&gt;nome-da-branch]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Após executar o comando &lt;code&gt;git checkout teste&lt;/code&gt;, podemos ver que a &lt;strong&gt;branch ativa é alternada&lt;/strong&gt;. A partir desse momento &lt;strong&gt;todo o trabalho commitado estará sendo enviado para a branch &lt;code&gt;teste&lt;/code&gt;&lt;/strong&gt; do repositório, sem impactar a branch &lt;code&gt;master/main&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjvk5byfkhrw271htk63g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjvk5byfkhrw271htk63g.png" alt="Captura de tela de um terminal Linux executando o comando " width="623" height="146"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;É possível criar quantas branches forem necessárias e podemos interagir com as branches criadas utilizando os comandos abaixo:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git checkout -b [nome-da-branch]&lt;/code&gt; -&amp;gt; cria uma nova branch com o nome especificado e já alterna para ela.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git branch -d [nome-da-branch]&lt;/code&gt; -&amp;gt; exclui a branch especificada.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git branch -m [novo-nome]&lt;/code&gt; -&amp;gt; altera o nome da branch atual para o nome especificado.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  7.3 Combinando branches (git merge)
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Quando finalizamos o trabalho&lt;/strong&gt; em uma &lt;strong&gt;branch diferente&lt;/strong&gt; e temos segurança de que as alterações feitas não ocasionaram problemas no código, &lt;strong&gt;podemos mergear&lt;/strong&gt; &lt;em&gt;(combinar)&lt;/em&gt; a branch atual com a branch &lt;code&gt;master/main&lt;/code&gt;, &lt;strong&gt;aplicando todas as mudanças da branch atual à branch principal do repositório&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Para realizar o &lt;strong&gt;merge&lt;/strong&gt; de uma branch à outra, devemos &lt;strong&gt;alternar para a branch que vai receber as alterações&lt;/strong&gt; e utilizar o comando abaixo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git merge &lt;span class="o"&gt;[&lt;/span&gt;nome-da-branch]
&lt;span class="c"&gt;# faz o merge da branch especificada na branch atual&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nos nossos exemplos, como estamos na branch &lt;code&gt;teste&lt;/code&gt;, &lt;strong&gt;devemos alternar para a branch &lt;code&gt;master&lt;/code&gt;&lt;/strong&gt; utilizando o comando &lt;code&gt;git checkout&lt;/code&gt; e então executar o comando &lt;code&gt;git merge&lt;/code&gt; com o nome da branch que desejamos combinar &lt;em&gt;("teste", nesse caso)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo05mis8hmqxvji3b6ida.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo05mis8hmqxvji3b6ida.png" alt="Captura de tela de um terminal Linux executando o comando " width="618" height="213"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Dessa forma, todo o trabalho feito na branch &lt;code&gt;teste&lt;/code&gt; &lt;em&gt;(a criação do arquivo &lt;code&gt;style.css&lt;/code&gt;, nesse caso)&lt;/em&gt; será combinado com a branch &lt;code&gt;master&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faj66touqdivfszcygj9j.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faj66touqdivfszcygj9j.gif" alt="GIF simulando o processo de merge entre duas branches" width="610" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  7.4 Conflitos no merge
&lt;/h3&gt;

&lt;p&gt;Combinando diferentes branches com o &lt;code&gt;git merge&lt;/code&gt; podemos nos deparar com alguns &lt;strong&gt;conflitos&lt;/strong&gt; nos casos em que &lt;strong&gt;um ou mais arquivos tenham sido alterados nas mesmas linhas&lt;/strong&gt; e a combinação não pode ser realizada de maneira &lt;strong&gt;automática&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd29kwtdbo6v3ygo0g8ug.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd29kwtdbo6v3ygo0g8ug.png" alt="Captura de tela de um terminal Linux executando o comando " width="669" height="120"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nesses casos, podemos executar o comando &lt;code&gt;git status&lt;/code&gt; para verificar &lt;strong&gt;quais arquivos&lt;/strong&gt; estão conflitando.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fecgflogjezg7tqagnxca.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fecgflogjezg7tqagnxca.png" alt="Captura de tela de um terminal Linux executando o comando " width="676" height="353"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Será necessário &lt;strong&gt;resolver os conflitos&lt;/strong&gt; antes de prosseguir com o merge, definindo quais alterações devem prevalecer ou refazendo as alterações para que sejam mutuamente comportadas. Para isso, &lt;strong&gt;o próprio GIT insere marcações dentro dos arquivos conflitantes&lt;/strong&gt; que auxiliam a resolução.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5xkf28erxmwm48riwro5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5xkf28erxmwm48riwro5.png" alt="Captura de tela do arquivo conflitante aberto em um editor de texto exibindo as marcações criadas pelo GIT para auxiliar na resolução dos conflitos" width="532" height="197"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Após resolver os conflitos, basta recolocar os arquivos modificados em stage, realizar o commit das novas versões sem conflitos e executar novamente o comando &lt;code&gt;git merge&lt;/code&gt; que tudo deve ser combinado sem maiores problemas.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Sincronizando com o repositório remoto &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Sabemos que é possível &lt;strong&gt;relacionar o nosso repositório local à um repositório remoto&lt;/strong&gt; para sincronizar todo o nosso trabalho remotamente e mantê-lo sempre &lt;strong&gt;atualizado&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Para isso, utilizaremos o comando &lt;code&gt;git push&lt;/code&gt;, que &lt;strong&gt;envia todos os commits do repositório local para o repositório remoto&lt;/strong&gt;, mas antes, precisamos &lt;strong&gt;configurar um repositório remoto apropriado&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  8.1 Configurando um repositório remoto
&lt;/h3&gt;

&lt;p&gt;Iniciar um &lt;strong&gt;repositório remoto&lt;/strong&gt; é bastante simples. Aqui vamos utilizar o &lt;strong&gt;GitHub&lt;/strong&gt; para isso.&lt;/p&gt;

&lt;p&gt;Primeiro, devemos &lt;strong&gt;iniciar um novo repositório vazio&lt;/strong&gt; em nossa conta do GitHub &lt;em&gt;(apenas escolhendo um nome e clicando em "Criar repositório")&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frv86b3tupeadctbuhl4a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frv86b3tupeadctbuhl4a.png" alt="Captura de tela da página de criação de repositórios no GitHub." width="727" height="837"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Após isso, precisamos &lt;strong&gt;configurar a relação entre o repositório remoto e o repositório local&lt;/strong&gt;, executando o comando abaixo dentro do nosso repositório local:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git remote add origin &lt;span class="o"&gt;[&lt;/span&gt;url-do-repositorio-remoto]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F63m0nfymn1tidgtrodlm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F63m0nfymn1tidgtrodlm.png" alt="Captura de tela de um terminal Linux executando o comando " width="800" height="85"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;git remote -v&lt;/code&gt; -&amp;gt; exibe a URL do repositório remoto conectado ao repositório local atualmente.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Com o repositório remoto &lt;strong&gt;conectado&lt;/strong&gt;, devemos &lt;strong&gt;alterar o nome da nossa branch&lt;/strong&gt; &lt;code&gt;master/main&lt;/code&gt; local para "main" com o comando &lt;code&gt;git branch -m main&lt;/code&gt; &lt;em&gt;(ignorar se a sua branch local já se chamar &lt;code&gt;main&lt;/code&gt;)&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faon7j7qsa26wkb56hjti.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faon7j7qsa26wkb56hjti.png" alt="Captura de tela de um terminal Linux executando o comando " width="618" height="144"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;É importante que a branch principal do repositório local tenha o mesmo nome da branch principal do repositório remoto ao qual vamos realizar o push.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Finalmente, após cumprir os passos acima, podemos &lt;strong&gt;sincronizar&lt;/strong&gt; nosso trabalho local com o repositório remoto pela primeira vez utilizando o comando abaixo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git push &lt;span class="nt"&gt;-u&lt;/span&gt; origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8tuxzcjceamo062qkhuq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8tuxzcjceamo062qkhuq.png" alt="Captura de tela de um terminal Linux executando o comando " width="686" height="73"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ao executar o comando &lt;code&gt;git push -u origin main&lt;/code&gt; pode ser necessário informar suas &lt;strong&gt;credenciais do GitHub&lt;/strong&gt; &lt;em&gt;(usuário e token de acesso)&lt;/em&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Se você não sabe o que é um &lt;strong&gt;token de acesso do GitHub&lt;/strong&gt;, ou ainda não tem seu token de acesso configurado, &lt;a href="https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic" rel="noopener noreferrer"&gt;clique aqui&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Também é possível contornar isso configurando a &lt;strong&gt;autenticação com o CLI do GitHub&lt;/strong&gt;. Saiba como &lt;a href="https://docs.github.com/en/get-started/getting-started-with-git/caching-your-github-credentials-in-git" rel="noopener noreferrer"&gt;clicando aqui&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Após &lt;strong&gt;autenticar&lt;/strong&gt;, o &lt;code&gt;git push&lt;/code&gt; deve ser executado com sucesso, sincronizando todos os commits do repositório local com o repositório remoto.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyiid2ip61vqvtk860pa3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyiid2ip61vqvtk860pa3.png" alt="Captura de tela de um terminal Linux exibindo a continuação do comando " width="686" height="323"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvgpzamg4umcx8xk1taso.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvgpzamg4umcx8xk1taso.png" alt="Captura de tela do repositório remoto no GitHub após receber o " width="800" height="231"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  8.2 Git push depois da primeira vez (git push)
&lt;/h3&gt;

&lt;p&gt;Depois de passar por todas as etapas acima, &lt;strong&gt;novas sincronizações&lt;/strong&gt; podem ser realizadas somente utilizando o comando &lt;code&gt;git push&lt;/code&gt;, sem que haja necessidade de passar qualquer parâmetro, como vemos abaixo.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fexa9y8e2ndprwx71ovvi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fexa9y8e2ndprwx71ovvi.png" alt="Captura de tela de um terminal Linux executando os comandos " width="800" height="456"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzm9pj2y4g9pi37y7hbgr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzm9pj2y4g9pi37y7hbgr.png" alt="Captura de tela do repositório remoto no GitHub após receber as novas atualizações." width="800" height="268"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Nesse caso, a autenticação necessária para realizar o &lt;code&gt;git push&lt;/code&gt; foi contornada utilizando o &lt;strong&gt;CLI do GitHub&lt;/strong&gt;. Saiba como &lt;a href="https://docs.github.com/en/get-started/getting-started-with-git/caching-your-github-credentials-in-git" rel="noopener noreferrer"&gt;clicando aqui&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  8.3 Atualizando o repositório local (git pull)
&lt;/h3&gt;

&lt;p&gt;Com um repositório remoto &lt;strong&gt;distribuído&lt;/strong&gt;, é possível que alterações sejam feitas &lt;strong&gt;remotamente&lt;/strong&gt; &lt;em&gt;(diretamente no repositório remoto)&lt;/em&gt;, fazendo com que nosso repositório local fique &lt;strong&gt;desatualizado&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Por isso, é muito importante &lt;strong&gt;atualizar o repositório local&lt;/strong&gt;, sincronizando quaisquer mudanças existentes no repositório remoto, &lt;strong&gt;garantindo que o código local esteja sempre em sua última versão disponível no repositório remoto&lt;/strong&gt;. Para isso, podemos utilizar o comando abaixo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git pull
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Imagine que um &lt;strong&gt;novo arquivo&lt;/strong&gt; &lt;code&gt;README.md&lt;/code&gt; foi criado &lt;strong&gt;diretamente no repositório remoto&lt;/strong&gt; e, com isso, nosso repositório local está desatualizado.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fciyaqur9kk7eejebcfqf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fciyaqur9kk7eejebcfqf.png" alt="Captura de tela do repositório remoto com um novo arquivo " width="800" height="439"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Dentro do repositório local, podemos &lt;strong&gt;sincronizar&lt;/strong&gt; as alterações do repositório remoto com o &lt;code&gt;git pull&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fetfhi8pxgbi5e34sydtz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fetfhi8pxgbi5e34sydtz.png" alt="Captura de tela de um terminal Linux executando o comando " width="677" height="364"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;As primeiras 7 linhas retornadas ao executar o comando &lt;code&gt;git pull&lt;/code&gt; são resultado do comando &lt;code&gt;git fetch&lt;/code&gt;. Ou seja, ao executar o comando &lt;code&gt;git pull&lt;/code&gt; sem executar o comando &lt;code&gt;git fetch&lt;/code&gt; previamente, o GIT executa ambos em conjunto para recuperar as atualizações do repositório remoto e sincronizá-las no repositório local.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git fetch&lt;/code&gt; -&amp;gt; Recupera as atualizações do repositório remoto, mas não sincroniza o repositório local (necessita do &lt;code&gt;git pull&lt;/code&gt;)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  9. Conclusão &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Tudo isso nos traz a certeza de que o GIT é um sistema de controle de versão necessário no dia a dia de um programador, e conhecer seus principais comandos e utilidades pode ser o divisor de águas em nossa senioridade técnica.&lt;br&gt;
Por fim, com os repositórios locais e remotos sincronizados e atualizados e com tudo o que aprendemos até agora, estamos prontos para seguir em frente com a praticidade desse incrível sistema de controle de versão.&lt;/p&gt;

&lt;h2&gt;
  
  
  10. Referências &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://git-scm.com/docs/git#_git_commands" rel="noopener noreferrer"&gt;Documentação oficial do GIT&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://youtu.be/ts-H3W1uLMM?si=-hKGkUmwgT2lZJwy" rel="noopener noreferrer"&gt;GIT: Mini Curso para Você Sair do Zero! (Aprenda em 45 Minutos) - Codigo Fonte TV&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Publicado originalmente em Inglês:&lt;/em&gt;&lt;br&gt;
&lt;a href="https://dev.to/basement/everything-that-you-need-to-know-about-git-2440"&gt;Everything you need to know about GIT&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>tutorial</category>
      <category>learning</category>
      <category>git</category>
    </item>
    <item>
      <title>Everything you need to know about GIT</title>
      <dc:creator>Renato Teixeira</dc:creator>
      <pubDate>Mon, 05 Feb 2024 14:30:00 +0000</pubDate>
      <link>https://forem.com/basementdevs/everything-that-you-need-to-know-about-git-2440</link>
      <guid>https://forem.com/basementdevs/everything-that-you-need-to-know-about-git-2440</guid>
      <description>&lt;p&gt;I'm sure you can imagine the importance of versioning code, so that we can &lt;strong&gt;revert changes&lt;/strong&gt; and &lt;strong&gt;recover lost data among other possibilities&lt;/strong&gt;.&lt;br&gt;
I bet you know someone &lt;em&gt;(not me hehe)&lt;/em&gt; who does version control with their files by creating copies of them with increasingly creative names...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsffhjyl41pfnjklivnsv.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsffhjyl41pfnjklivnsv.gif" alt="GIF that simulates the duplication of a file with different names. Example: article, article-finalversion, etc." width="610" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This was probably how anyone would do version control with their code as well before 1972, with the release of &lt;strong&gt;SCCS &lt;em&gt;(Source Code Control System)&lt;/em&gt;&lt;/strong&gt;, one of the first &lt;strong&gt;centralized&lt;/strong&gt; version control software ever released.&lt;/p&gt;

&lt;p&gt;But we're not here to talk about SCCS, what really interests us now is &lt;strong&gt;GIT&lt;/strong&gt;, the &lt;strong&gt;distributed&lt;/strong&gt; open-source version control software that celebrates its 20th anniversary next year &lt;em&gt;(07/04/2005)&lt;/em&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Table of contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;1. What's GIT?&lt;/li&gt;
&lt;li&gt;2. How does GIT work?&lt;/li&gt;
&lt;li&gt;3. Installing GIT&lt;/li&gt;
&lt;li&gt;4. Configuring GIT&lt;/li&gt;
&lt;li&gt;5. Starting a local repository&lt;/li&gt;
&lt;li&gt;6. Working with GIT&lt;/li&gt;
&lt;li&gt;7. Knowing branches&lt;/li&gt;
&lt;li&gt;8. Syncing with the remote repository&lt;/li&gt;
&lt;li&gt;9. Conclusion&lt;/li&gt;
&lt;li&gt;10. References&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  1. What's GIT? &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;GIT is an open-source &lt;strong&gt;distributed&lt;/strong&gt; version control system launched in 2005 and developed by Linus Torvald &lt;em&gt;(yh, the Linux kernel creator)&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;With GIT, we can locally &lt;strong&gt;control the versions of a project&lt;/strong&gt; &lt;em&gt;(in the working folder)&lt;/em&gt; and synchronize all changes to a remote repository &lt;em&gt;(on GitHub, for example)&lt;/em&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  2. How does GIT work? &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Imagine a &lt;strong&gt;physical&lt;/strong&gt; file cabinet where there's a folder with all the project files. Whenever someone needs to manipulate a file, they have to pick it up, &lt;strong&gt;removing it from the folder and returning it to the folder after finishing&lt;/strong&gt;. So, it is &lt;strong&gt;impossible&lt;/strong&gt; for two people to work on the same file, completely avoiding any possible conflicts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;BUT THAT'S NOT HOW GIT WORKS!&lt;/strong&gt; &lt;em&gt;(thank God)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This is how a &lt;strong&gt;CENTRALIZED&lt;/strong&gt; version control system works, in which the user needs to &lt;strong&gt;"check-out"&lt;/strong&gt; and &lt;strong&gt;"check-in"&lt;/strong&gt; files, i.e. whenever someone needs to work on a specific file, they need to check-out that file, &lt;strong&gt;removing it from the repository&lt;/strong&gt;, and then check-in the file once the work is done, &lt;strong&gt;returning it to the repository&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F26a9j0m4pcu5prb0kauo.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F26a9j0m4pcu5prb0kauo.gif" alt="GIF that simulates the operation of a centralized version control system." width="610" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In a &lt;strong&gt;DISTRIBUTED&lt;/strong&gt; system like &lt;strong&gt;GIT&lt;/strong&gt;, it's possible for several people to access files from the same remote repository. Whenever someone needs to manipulate a file, they can simply &lt;strong&gt;clone&lt;/strong&gt; it &lt;em&gt;(or clone the entire repository)&lt;/em&gt; locally to their machine, and then send the modifications back to the remote repository. This makes it possible for &lt;strong&gt;several people to work on the same project&lt;/strong&gt;, even manipulating the &lt;strong&gt;same files&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnb0x0u9kc6m7z2hz7zfj.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnb0x0u9kc6m7z2hz7zfj.gif" alt="GIF that simulates the operation of a distributed version control system." width="610" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is what allows the distribution of large &lt;strong&gt;open-source&lt;/strong&gt; projects, with people from different parts of the world working on the same project, managing modifications and possible conflicts &lt;em&gt;(yes, merge conflicts can happen here)&lt;/em&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  3. Installing GIT &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;GIT&lt;/strong&gt; is available for the main operating systems &lt;em&gt;(Windows, Linux, MacOs...)&lt;/em&gt; with a very simple installation process, which can be done by &lt;strong&gt;command line&lt;/strong&gt; or through the &lt;strong&gt;official installer&lt;/strong&gt; at &lt;a href="https://git-scm.com/" rel="noopener noreferrer"&gt;git-scm.com&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  3.1 On Windows
&lt;/h3&gt;

&lt;p&gt;To install GIT on Windows, simply go to the official website and &lt;a href="https://git-scm.com/download/win" rel="noopener noreferrer"&gt;download the installer&lt;/a&gt;. Then just &lt;strong&gt;follow the instructions&lt;/strong&gt; and everything should be fine then we'll be able to use the GIT commands in our terminal.&lt;/p&gt;
&lt;h3&gt;
  
  
  3.2 On Linux
&lt;/h3&gt;

&lt;p&gt;For Linux, we can install &lt;strong&gt;GIT&lt;/strong&gt; using the &lt;strong&gt;command&lt;/strong&gt; below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;git-all
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By doing this, &lt;strong&gt;GIT&lt;/strong&gt; must be ready to run in our terminal.&lt;/p&gt;

&lt;h3&gt;
  
  
  3.3 On MacOS
&lt;/h3&gt;

&lt;p&gt;For Mac, the easiest way to install &lt;strong&gt;GIT&lt;/strong&gt; is to install &lt;a href="https://brew.sh/" rel="noopener noreferrer"&gt;Homebrew&lt;/a&gt; and then run the &lt;strong&gt;command&lt;/strong&gt; below in the terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;brew &lt;span class="nb"&gt;install &lt;/span&gt;git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then &lt;strong&gt;GIT&lt;/strong&gt; must be ready to run in our terminal.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Configuring GIT &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;After installing, it's important to &lt;strong&gt;configure GIT&lt;/strong&gt; with the &lt;strong&gt;commands&lt;/strong&gt; below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; user.name &lt;span class="s2"&gt;"[username]"&lt;/span&gt;
&lt;span class="c"&gt;# e.g. John Doe&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; user. email &lt;span class="s2"&gt;"[email@email.com]"&lt;/span&gt;
&lt;span class="c"&gt;# e.g. johndoe@email.com&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Also, it's possible to configure specific users for certain local repositories by removing the &lt;code&gt;--global&lt;/code&gt; tag.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  5. Starting a local repository &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;With &lt;strong&gt;GIT&lt;/strong&gt; configured, we can &lt;strong&gt;start our local repository&lt;/strong&gt;. To do this, we can &lt;strong&gt;start a new repository from scratch&lt;/strong&gt; or &lt;strong&gt;clone an existing remote repository&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  5.1 Starting from scratch (git init)
&lt;/h3&gt;

&lt;p&gt;To start a new repository, simply navigate to the desired repository &lt;strong&gt;root folder&lt;/strong&gt; and run the command below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiw35xe9jwrwzo937to5b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiw35xe9jwrwzo937to5b.png" alt="Screenshot of a Linux terminal running the " width="771" height="80"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By doing this, a &lt;code&gt;.git&lt;/code&gt; directory will be created inside the project folder, which will be &lt;strong&gt;responsible for the version control&lt;/strong&gt; in the working folder of this local repository.&lt;/p&gt;

&lt;h3&gt;
  
  
  5.2 Cloning an existing repository (git clone)
&lt;/h3&gt;

&lt;p&gt;Cloning an existing remote repository is as easy as starting a new one from scratch. To do this, simply use the &lt;code&gt;git clone&lt;/code&gt; command, with the &lt;strong&gt;remote repository URL&lt;/strong&gt; to be cloned inside the folder where we want to download the repository:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone &lt;span class="o"&gt;[&lt;/span&gt;repository-url]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnlt8rtua4ri7kpnna5el.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnlt8rtua4ri7kpnna5el.png" alt="Screenshot of a Linux terminal running the " width="800" height="170"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then the entire repository must be &lt;strong&gt;cloned&lt;/strong&gt; to our local machine and &lt;strong&gt;automatically linked to the related remote repository&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;With a cloned repository, we will no longer need to use the &lt;code&gt;git remote&lt;/code&gt; command in the future.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  6. Working with GIT &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Within our &lt;strong&gt;local repository&lt;/strong&gt;, we can create the files needed for our project, but they &lt;strong&gt;won't be automatically synced by GIT&lt;/strong&gt;, we'll need to report it when there are any changes to be versioned.&lt;/p&gt;

&lt;p&gt;Thus, we can &lt;strong&gt;manipulate&lt;/strong&gt; the files as we wish and &lt;strong&gt;after finishing the desired changes&lt;/strong&gt;, &lt;strong&gt;send the updated files to GIT&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;To do this, it is important to understand that there is a &lt;strong&gt;3 stage infinite flow&lt;/strong&gt; &lt;em&gt;(yes, infinite)&lt;/em&gt; in version control:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;              MODIFY -&amp;gt; STAGE -&amp;gt; COMMIT
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;MODIFY:&lt;/strong&gt; The first stage of version control, this is where we find the &lt;strong&gt;files that have changed&lt;/strong&gt; compared to the last available version.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;STAGE:&lt;/strong&gt; The second stage of version control, this is where we place &lt;strong&gt;modified files that we want to add&lt;/strong&gt; to our next commit.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;COMMIT:&lt;/strong&gt; Final stage of version control, when we &lt;strong&gt;confirm the changes&lt;/strong&gt;, sending the modified files that were in stage to the local repository.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After committing the modified files, we have a &lt;strong&gt;new version&lt;/strong&gt; available in the local repository, which can again receive updates, going one more time to &lt;em&gt;"modified"&lt;/em&gt;, then placed in &lt;em&gt;"stage"&lt;/em&gt; and, again, being &lt;em&gt;"committed"&lt;/em&gt;, confirming a newer version and so on &lt;em&gt;(and therefore, "infinite" lol)&lt;/em&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It's important to notice that a commit doesn't overwrite the old version of the modified files, but includes the new version with a pointer to the last version, thus keeping track of the versions of each file tracked by GIT.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  6.1 Adding and commiting (git add and git commit)
&lt;/h3&gt;

&lt;p&gt;Although it might sounds complex, performing the version control flow is &lt;strong&gt;very simple&lt;/strong&gt;. Since the desired modifications are completed, we &lt;strong&gt;add the modified files that we want to commit on stage&lt;/strong&gt; with the command below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add &lt;span class="o"&gt;[&lt;/span&gt;filename]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;git add -A&lt;/code&gt; -&amp;gt; adds all modified files to stage at once.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git add *.[extensão-do-arquivo]&lt;/code&gt; -&amp;gt; adds all modified files with the specified file extension to stage at once (e.g. &lt;code&gt;git add *.html&lt;/code&gt;)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We can check our current local repository &lt;strong&gt;status&lt;/strong&gt; at any time using the &lt;code&gt;git status&lt;/code&gt; command:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe28lg7wym8s0woytgzqz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe28lg7wym8s0woytgzqz.png" alt="Screenshot of a Linux terminal running the " width="789" height="258"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note that when we run &lt;code&gt;git status&lt;/code&gt; inside the repository &lt;strong&gt;after creating a new file&lt;/strong&gt;, the new file is shown as &lt;em&gt;"Untracked"&lt;/em&gt;. This means that this file is &lt;strong&gt;fresh new&lt;/strong&gt; and still needs to be added to any commit in order to be &lt;strong&gt;tracked&lt;/strong&gt; by &lt;strong&gt;GIT&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It's possible to let GIT ignore specific files or folders within the repository. To do this, we can simply add a file to the root folder called &lt;code&gt;.gitignore&lt;/code&gt; and write the name of the files or folders that should be ignored inside it.&lt;/p&gt;

&lt;p&gt;CAUTION: Ignored files and folders will no longer appear to the GIT track, not even as "Untracked". To reset the tracking, simply delete the desired names from the &lt;code&gt;.gitignore&lt;/code&gt; file.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To include a file, we can run the &lt;code&gt;git add&lt;/code&gt; command with the name of the file that we want to add &lt;em&gt;("index.html" in this case)&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpz1hnk9gpnxtv2s8xort.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpz1hnk9gpnxtv2s8xort.png" alt="Screenshot of a Linux terminal running the command " width="633" height="260"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This way, by re-running &lt;code&gt;git status&lt;/code&gt; we can see that the new file has been added to &lt;em&gt;"stage"&lt;/em&gt; and is &lt;strong&gt;finally ready to be sent in our next commit&lt;/strong&gt;, which can be done using the command below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"[descriptive-message]"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Commits have unique IDs (hash codes) and are &lt;strong&gt;IMMUTABLE&lt;/strong&gt;, i.e. they cannot be modified once they have been confirmed.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git commit -a&lt;/code&gt; -&amp;gt; performs a direct commit, adding all the modified files to stage and committing them.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;After successfully committing a file&lt;/strong&gt;, when running &lt;code&gt;git status&lt;/code&gt; we notice that &lt;strong&gt;there are no more modified files to be uploaded&lt;/strong&gt;, since all the modifications were effectively saved in our local repository with our last &lt;strong&gt;commit&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fryqqs4mi46hxtuex199i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fryqqs4mi46hxtuex199i.png" alt="Screenshot of a Linux terminal running the command " width="773" height="191"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also, it's possible to &lt;strong&gt;verify the changes made&lt;/strong&gt; by reviewing the repository's commit log, using the &lt;code&gt;git log&lt;/code&gt; command, which shows some metadata of all the commits made, such as the hash code, branch, author, date, etc.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fljvj9se6srxslsu8vsj7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fljvj9se6srxslsu8vsj7.png" alt="Screenshot of a Linux terminal running the command " width="672" height="168"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This whole process can be repeated to add new files that are needed for our project, modify them and send them to the local repository by making new commits.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2uez3henix8kchperuw8.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2uez3henix8kchperuw8.gif" alt="GIF that simulates multiple commits in a GIT branch." width="610" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;git log -N&lt;/code&gt; -&amp;gt; displays a log with the last N commits.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git log [branch-A] [branch-B]&lt;/code&gt; -&amp;gt; displays a log of commits that are in "branch-B" but not in "branch-A".&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git log --follow [filename]&lt;/code&gt; -&amp;gt; displays a log of commits that changed the specified file, even if it has changed its name.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git diff&lt;/code&gt; -&amp;gt; lists the changes made compared to the latest available version in the repository.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git diff [nome-do-arquivo]&lt;/code&gt; -&amp;gt; lists the changes made to the specified file in relation to its last available version in the repository.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  6.2 Undo changes before and after commiting
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Before a commit is made&lt;/strong&gt;, any changes made to the local repository can be undone or changed, but &lt;strong&gt;once the commit is made, it cannot be changed&lt;/strong&gt;. This is because commits are &lt;strong&gt;immutable objects&lt;/strong&gt;, meaning that it is impossible to edit or change the data in a commit.&lt;/p&gt;

&lt;p&gt;However, it is &lt;strong&gt;possible to make new commits&lt;/strong&gt; that undo changes, or correct incorrect information in previous commits. In either way, we can use one of the commands below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;filename]
&lt;span class="c"&gt;# Discards changes made to the local file before the commit (irreversible action)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git reset &lt;span class="nt"&gt;--hard&lt;/span&gt; HEAD
&lt;span class="c"&gt;# Discards changes made to a file that is in stage (before the commit)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git reset &lt;span class="nt"&gt;--hard&lt;/span&gt; HEAD~1
&lt;span class="c"&gt;# Discards the last commit made in the local repository (only the last commit)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git commit &lt;span class="nt"&gt;--amend&lt;/span&gt;
&lt;span class="c"&gt;# Creates a new commit, replacing the last commit made in the local repository&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git revert &lt;span class="o"&gt;[&lt;/span&gt;commit-hash]
&lt;span class="c"&gt;# Creates a new commit, reverting the changes of the specified commit&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  7. Knowing branches &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;branch&lt;/strong&gt; is nothing more than a &lt;strong&gt;ramification&lt;/strong&gt; of the repository, and so far all actions have been performed on the branch &lt;code&gt;master/main'&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;By default, the first branch created in the repository is the &lt;code&gt;master/main&lt;/code&gt;, which is the main branch of the repository.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  7.1 Why use branches?
&lt;/h3&gt;

&lt;p&gt;It may not seem like much at first, but &lt;strong&gt;branches give enormous power to the project development&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Imagine we're developing a web platform, and we want to &lt;strong&gt;test a new feature&lt;/strong&gt;, but our repository is already &lt;strong&gt;hosted or shared&lt;/strong&gt; with other people, and any problematic change could cause a bad experience for them. What can we do?&lt;/p&gt;

&lt;p&gt;If you've been thinking about &lt;strong&gt;copy and paste&lt;/strong&gt; the project folder, creating a new &lt;strong&gt;"test version"&lt;/strong&gt;, you're right! Well, almost...&lt;/p&gt;

&lt;p&gt;With GIT, we can do something similar with branches. Since they are &lt;strong&gt;branches&lt;/strong&gt;, we can simply &lt;strong&gt;create a new branch called "test"&lt;/strong&gt;, and thus have a version of our project in a completely &lt;strong&gt;isolated branch&lt;/strong&gt;, ready to be flipped &lt;strong&gt;without risking the main branch&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fszc081nndoi18vklty5r.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fszc081nndoi18vklty5r.gif" alt="GIF that simulates the creation of a new branch with new commits." width="610" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  7.2 Creating branches (git branch)
&lt;/h3&gt;

&lt;p&gt;Creating a &lt;strong&gt;branch&lt;/strong&gt; means creating a parallel copy of the repository that can be worked on independently, without affecting the &lt;code&gt;master/main&lt;/code&gt; branch. To do this, we can simply run the command below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git branch &lt;span class="o"&gt;[&lt;/span&gt;branch-name]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Running the &lt;code&gt;git branch&lt;/code&gt; command without a specific branch name must display the list of available branches in the repository, with a "*" marking the branch that's currently in use.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Before running the &lt;code&gt;git branch test&lt;/code&gt; command, the &lt;code&gt;git branch&lt;/code&gt; command only returned the &lt;code&gt;master&lt;/code&gt; branch.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvqpdrtvhze9qhr31ewbh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvqpdrtvhze9qhr31ewbh.png" alt="Screenshot of a Linux terminal running the " width="558" height="172"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After creating a new branch, we can run the command below to switch between the available branches:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout &lt;span class="o"&gt;[&lt;/span&gt;branch-name]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After running the &lt;code&gt;git checkout test&lt;/code&gt; command we can see that the &lt;strong&gt;active branch is switched&lt;/strong&gt;. From that moment on, &lt;strong&gt;all committed information will be sent to the &lt;code&gt;test&lt;/code&gt; branch&lt;/strong&gt; of the repository, without affecting the branch &lt;code&gt;master/main&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fegau7y81leig8za36myi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fegau7y81leig8za36myi.png" alt="Screenshot of a Linux terminal running the " width="582" height="150"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It's possible to create as many branches as we need, and we can interact with the existing branches using the commands below:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git checkout -b [branch-name]&lt;/code&gt; -&amp;gt; creates a new branch with the given name and directly switches to it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git branch -d [branch-name]&lt;/code&gt; -&amp;gt; deletes the specified branch.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git branch -m [new-name]&lt;/code&gt; -&amp;gt; changes the name of the current branch to the given name.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  7.3 Merging branches (git merge)
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;When finished working&lt;/strong&gt; on a &lt;strong&gt;different branch&lt;/strong&gt;, and we're sure that the changes we've made haven't caused any problems in the project, we can &lt;strong&gt;merge&lt;/strong&gt; the current branch in the &lt;code&gt;master/main&lt;/code&gt; branch, &lt;strong&gt;applying all the changes from the current branch to the main branch of the repository&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;To &lt;strong&gt;merge&lt;/strong&gt; branches, we need to &lt;strong&gt;switch to the branch that will receive the changes&lt;/strong&gt; and run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git merge &lt;span class="o"&gt;[&lt;/span&gt;branch-name]
&lt;span class="c"&gt;# Merge the given branch into the active branch&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, since we are on the branch &lt;code&gt;test&lt;/code&gt;, &lt;strong&gt;we should switch to the branch &lt;code&gt;master&lt;/code&gt;&lt;/strong&gt; using the &lt;code&gt;git checkout&lt;/code&gt; command, and then run the &lt;code&gt;git merge&lt;/code&gt; command with the name of the branch we want to merge &lt;em&gt;("test", in this case)&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa6tqap1uu5gjipkety6w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa6tqap1uu5gjipkety6w.png" alt="Screenshot of a Linux terminal running the command " width="618" height="215"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By doing this, all the work done on the branch &lt;code&gt;test&lt;/code&gt; &lt;em&gt;(in this case, the creation of the &lt;code&gt;style.css&lt;/code&gt; file)&lt;/em&gt; will be merged in the branch &lt;code&gt;master&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3hs17m005ogm0qlbedjy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3hs17m005ogm0qlbedjy.gif" alt="GIF that simulates the merge process between two branches." width="610" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  7.4 Merge conflicts
&lt;/h3&gt;

&lt;p&gt;Merging different branches with &lt;code&gt;git merge&lt;/code&gt; can lead to some &lt;strong&gt;conflicts&lt;/strong&gt; in cases where &lt;strong&gt;one or more files have been changed on the same lines&lt;/strong&gt; and the merge cannot be done &lt;strong&gt;automatically&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9mwedudsff1yf8kpzguc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9mwedudsff1yf8kpzguc.png" alt="Screenshot of a Linux terminal running the " width="692" height="126"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When this happens, we can run the &lt;code&gt;git status&lt;/code&gt; command to check &lt;strong&gt;which files&lt;/strong&gt; are in conflict.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhcfpmta2yiy1xpyc729u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhcfpmta2yiy1xpyc729u.png" alt="Screenshot of a Linux terminal running the " width="681" height="345"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We'll need to &lt;strong&gt;solve the conflicts&lt;/strong&gt; before proceeding with the merge, either by defining which changes should take place, or by reviewing the changes so that they are mutually compatible. To do this, &lt;strong&gt;GIT will insert markers into the conflicting files&lt;/strong&gt; to help with the resolution.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa0e727le3ogmhtuq0g7w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa0e727le3ogmhtuq0g7w.png" alt="Screenshot of the conflicting file opened in a text editor, showing the markers created by GIT to help resolve the conflicts." width="453" height="189"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After solving the conflicts, we just need to put the modified files back on stage, commit the new no-conflict versions, and run the &lt;code&gt;git merge&lt;/code&gt; command again, which must successfully merge without any problems.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Syncing with the remote repository &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;We already know that it's possible to &lt;strong&gt;connect our local repository to a remote repository&lt;/strong&gt; and synchronize all our work remotely, keeping it &lt;strong&gt;up to date&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;To do this we'll need to run the &lt;code&gt;git push&lt;/code&gt; command, which &lt;strong&gt;sends all commits from the local repository to the remote repository&lt;/strong&gt;, but first we need to **configure a remote repository.&lt;/p&gt;

&lt;h3&gt;
  
  
  8.1 Configuring the remote repository
&lt;/h3&gt;

&lt;p&gt;Starting a &lt;em&gt;remote repository&lt;/em&gt; is quite simple. Here we'll use &lt;strong&gt;GitHub&lt;/strong&gt; to do it.&lt;/p&gt;

&lt;p&gt;First, we need to &lt;strong&gt;start a new empty repository&lt;/strong&gt; in our GitHub account &lt;em&gt;(just by choosing a name and clicking "Create repository")&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fug1aw5eq15du36vd1hri.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fug1aw5eq15du36vd1hri.png" alt="Screenshot of the repository creation page on GitHub." width="729" height="844"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we need to &lt;strong&gt;configure the relationship between the remote repository and the local repository&lt;/strong&gt; by running the following command inside our local repository:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git remote add origin &lt;span class="o"&gt;[&lt;/span&gt;remote-repository-url]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frhrlfg0f0pgljl5b18vl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frhrlfg0f0pgljl5b18vl.png" alt="Screenshot of a Linux terminal running the " width="800" height="87"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;git remote -v&lt;/code&gt; -&amp;gt; shows the URL of the remote repository that's actually connected to the local repository.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;With the remote repository properly &lt;strong&gt;connected&lt;/strong&gt;, we need to &lt;strong&gt;change the name of our local branch &lt;code&gt;master/main&lt;/code&gt;&lt;/strong&gt; to "main" with the command &lt;code&gt;git branch -m main&lt;/code&gt; &lt;em&gt;(ignore this step if your local branch is already called &lt;code&gt;main&lt;/code&gt;)&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff0al7joro01pch0ac124.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff0al7joro01pch0ac124.png" alt="Screenshot of a Linux terminal running the " width="618" height="150"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It's important to keep the main branch of the local repository with the same name as the main branch of the remote repository to which we are pushing.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Finally, after completing the above steps, we can &lt;strong&gt;sync&lt;/strong&gt; our local repository with the remote repository for the first time using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git push &lt;span class="nt"&gt;-u&lt;/span&gt; origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffvkdyis8y989xron52nc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffvkdyis8y989xron52nc.png" alt="Screenshot of a Linux terminal running the " width="676" height="71"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we run the &lt;code&gt;git push -u origin main&lt;/code&gt; command, we may need to enter our &lt;strong&gt;GitHub credentials&lt;/strong&gt; &lt;em&gt;(user and access token)&lt;/em&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you don't know what a &lt;strong&gt;GitHub access token&lt;/strong&gt; is, or you don't have one access token set up, &lt;a href="https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic" rel="noopener noreferrer"&gt;click here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We can also work around this by configuring &lt;strong&gt;authentication using the GitHub CLI&lt;/strong&gt;. Find out how &lt;a href="https://docs.github.com/en/get-started/getting-started-with-git/caching-your-github-credentials-in-git" rel="noopener noreferrer"&gt;by clicking here&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After &lt;strong&gt;authenticating&lt;/strong&gt;, &lt;code&gt;git push&lt;/code&gt; should run successfully, synchronizing all commits in the local repository with the remote repository.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvp7q4htszkzrfc6vepcl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvp7q4htszkzrfc6vepcl.png" alt="Screenshot of a Linux terminal showing the continuation of the " width="676" height="296"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2rqfhi6s6jh369tseh5y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2rqfhi6s6jh369tseh5y.png" alt="Screenshot of the remote repository on GitHub after receiving the " width="800" height="233"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  8.2 Git push after the first time (git push)
&lt;/h3&gt;

&lt;p&gt;After going through all the above steps, &lt;strong&gt;new syncs&lt;/strong&gt; can be done using the &lt;code&gt;git push&lt;/code&gt; command alone, without any additional parameters, like shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faoatcspiwosywih07nsm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faoatcspiwosywih07nsm.png" alt="Screenshot of a Linux terminal running the " width="786" height="498"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjskxpghboi62mqw2qcb2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjskxpghboi62mqw2qcb2.png" alt="Screenshot of the remote repository on GitHub after receiving the new updates." width="800" height="268"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In this case, the authentication needed to run the command &lt;code&gt;git push&lt;/code&gt; was bypassed using the &lt;strong&gt;GitHub CLI&lt;/strong&gt;. You can find out how by &lt;a href="https://docs.github.com/en/get-started/getting-started-with-git/caching-your-github-credentials-in-git" rel="noopener noreferrer"&gt;clicking here&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  8.3 Updating the local repository (git pull)
&lt;/h3&gt;

&lt;p&gt;With a &lt;strong&gt;distributed&lt;/strong&gt; remote repository, it's possible for changes to be made &lt;strong&gt;remotely&lt;/strong&gt; &lt;em&gt;(directly in the remote repository)&lt;/em&gt;, causing our local repository to become &lt;strong&gt;outdated&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Thinking about that, it's very important to &lt;strong&gt;update the local repository&lt;/strong&gt; and sync any changes that we got in the remote repository, &lt;strong&gt;ensuring that the local project is always with the latest version available in the remote repository&lt;/strong&gt;. To do this we can run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git pull
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Imagine that a &lt;strong&gt;new file&lt;/strong&gt; &lt;code&gt;README.md&lt;/code&gt; has been created &lt;strong&gt;directly in our remote repository&lt;/strong&gt; and because of that our local repository is now outdated.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhccw00vyr7j6lcfm02d2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhccw00vyr7j6lcfm02d2.png" alt="Screenshot of the remote repository with a new README.md file added remotely." width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Within the local repository we can &lt;strong&gt;synchronize&lt;/strong&gt; the changes from the remote repository using &lt;code&gt;git pull&lt;/code&gt; as mentioned above.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fit9ylx1imd94yey5d0wd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fit9ylx1imd94yey5d0wd.png" alt="Screenshot of a Linux terminal running the " width="677" height="364"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The first 7 lines returned when we run the &lt;code&gt;git pull&lt;/code&gt; command are the return of the &lt;code&gt;git fetch&lt;/code&gt; command. In other words, if we run the &lt;code&gt;git pull&lt;/code&gt; command without first running the &lt;code&gt;git fetch&lt;/code&gt; command, GIT will run both together to retrieve the updates from the remote repository and synchronize them to the local repository.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git fetch&lt;/code&gt; -&amp;gt; fetch updates from the remote repository, but does not sync the local repository (requires &lt;code&gt;git pull&lt;/code&gt;).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  9. Conclusion &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;All this leads us to the certainty that GIT is a version control system that is necessary in the daily life of a programmer, and knowing its main commands and uses can be the turning point in our technical seniority. Finally, with the local and remote repositories synced and updated and with everything we've learned so far, we're ready to move forward with the practicality of this awesome version control system.&lt;/p&gt;

&lt;h2&gt;
  
  
  10. References &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://git-scm.com/docs/git#_git_commands" rel="noopener noreferrer"&gt;GIT's official documentation.&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://youtu.be/ts-H3W1uLMM?si=-hKGkUmwgT2lZJwy" rel="noopener noreferrer"&gt;[PT-BR] GIT: Mini course to get you started (learn in 45 minutes) - Codigo Fonte TV&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>beginners</category>
      <category>tutorial</category>
      <category>learning</category>
      <category>git</category>
    </item>
  </channel>
</rss>
