├── .gitignore ├── Português └── README.markdown └── README.markdown /.gitignore: -------------------------------------------------------------------------------- 1 | # System Files 2 | .DS_Store 3 | Thumbs.db -------------------------------------------------------------------------------- /Português/README.markdown: -------------------------------------------------------------------------------- 1 | # Git Cheatsheet (Fundamentos) 2 | 3 | Esta cheatsheet é uma lista dos comandos Git mais usados por nós, além de conter informações úteis para quem está começando. 4 | 5 | *Quer aprender mais sobre o terminal? Há uma lista dos comandos e atalhos mais usados por nós no [Terminal do macOS](https://github.com/0nn0/terminal-mac-cheatsheet/tree/master/Português).* 6 | 7 | ## Glossário 8 | 9 | | Palavra-chave | Descrição | 10 | | -------------------------- | -------------------------------------------------------------------------------------------------------- | 11 | | git | Sistema de controle de versão distribuída de código aberto usado para armazenar código em repositórios | 12 | | GitHub, GitLab e Bitbucket | Plataformas para hospedagem de repositórios Git | 13 | | staging | Arquivos ou diretórios que você deseja *commitar* | 14 | | commit | Salva todos os arquivos ou diretórios *staged* no seu repositório local | 15 | | branch | Ramifica o desenvolvimento de forma independente para que recursos possam ser desenvolvidos isoladamente | 16 | | clone | Clona os *commits* e as *branches* da versão remota do repositório para uma nova versão local | 17 | | remote | Versão remota e comum a todos os colaboradores | 18 | | fork | Copia um repositório pertencente a outro usuário gerando um repositório em seu nome | 19 | | pull request | Solicita a fundição de suas contribuições a um repositório | 20 | | HEAD | Sua posição no diretório de trabalho atual | 21 | 22 | ## Configuração 23 | 24 | | Comando | Descrição | 25 | | ----------------------------------------- | ---------------------------------------------------------------------- | 26 | | `git config --global user.name [nome]` | Define o nome do autor a ser usado em todas as *commits* | 27 | | `git config --global user.email [e-mail]` | Define o endereço de e-mail do autor a ser usado em todas as *commits* | 28 | | `git config color.ui true` | Altera a cor da UI do terminal | 29 | 30 | ## Comandos Principais 31 | 32 | | Comando | Descrição | 33 | | --------------------------- | ----------------------------------------------------------------------------------------- | 34 | | `git init [diretório]` | Cria um novo repositório local | 35 | | `git clone [repo]` | Cria uma cópia local do repositório remoto | 36 | | `git add [diretório]` | Prepara o diretório para o *commit* | 37 | | `git add [arquivo]` | Prepara o arquivo para o *commit* | 38 | | `git add -A` | Prepara todos os arquivos alterados para o *commit* | 39 | | `git add .` | Prepara os arquivos novos e os com modificação e ignora os deletados para o *commit* | 40 | | `git add -u` | Prepara os arquivos deletados e os com modificação e ignora os novos para o *commit* | 41 | | `git commit -m "[mensagem]"` | *Commita* todos os arquivos e diretórios que foram preparados para o *commit* | 42 | | `git status` | Mostra o status dos arquivos ou diretórios como não rastreados, modificados ou preparados | 43 | 44 | ## Sincronização de Alterações 45 | 46 | | Comando | Descrição | 47 | | ----------- | ---------------------------------------------------------------------------------- | 48 | | `git fetch` | Baixa todo o histórico das *branches* remotas | 49 | | `git merge` | Anexa a *branch* remota na *branch* local | 50 | | `git pull` | Atualiza a *branch* local com os novos *commits* da *branch* remota correspondente | 51 | | `git push` | Envia todos os *commits* locais para o repositório remoto | 52 | 53 | *Dica: `git pull` é a combinação de `git fetch` com `git merge`* 54 | 55 | ## Desfazer Alterações 56 | 57 | | Comando | Descrição | 58 | | --------------------------- | ------------------------------------------------------------------------- | 59 | | `git checkout -- [arquivo]` | Substitue o arquivo pelo conteúdo da *HEAD* | 60 | | `git revert [commit]` | Cria um novo *commit* que desfaz as alterações feitas em [commit] | 61 | | `git reset [arquivo]` | Remove o [arquivo] da área de preparação | 62 | | `git reset --hard HEAD` | Remove todas as alterações locais no diretório de trabalho atual | 63 | | `git reset --hard [commit]` | Redefine o *HEAD* para o *commit* anterior e descarta todas as alterações | 64 | 65 | ## Branches 66 | 67 | | Comando | Descrição | 68 | | -------------------------- | ------------------------------------------ | 69 | | `git branch [branch]` | Cria uma nova *branch* | 70 | | `git checkout [branch]` | Vai à *branch* | 71 | | `git checkout [branch] -b` | Cria e vai à nova *branch* | 72 | | `git merge [branch]` | Anexa a *branch* [branch] à *branch* atual | 73 | | `git branch -d [branch]` | Deleta a *branch* | 74 | | `git push origin [branch]` | Envia a *branch* para o repositório remoto | 75 | | `git branch` | Lista as *branches* locais | 76 | | `git branch -r` | Lista as *branches* remotas | 77 | | `git branch -a` | Lista as *branches* locais e remotas | 78 | 79 | ## Histórico 80 | 81 | | Comando | Descrição | 82 | | -------------------------- | ------------------------------------------------------------------- | 83 | | `git log` | Lista o histórico de versões da *branch* atual | 84 | | `git log --author=[nome]` | Lista o histórico de versões da *branch* atual filtrada por autor | 85 | | `git log --oneline` | Lista o histórico de versões da *branch* atual de forma compacta | 86 | | `git show [commit]` | Lista os metadados e alterações feitas em um *commit* específico | 87 | | `git blame [arquivo]` | Mostra quem fez alterações em um arquivo e quando elas foram feitas | | 88 | 89 | ## Gitignore 90 | 91 | Adicionar o arquivo reservado para o sistema `.gitignore` ao seu diretório permite que você opte pela exclusão de certos arquivos de futuros *commits*. Este arquivo deve ficar sempre na raiz do seu repositório. 92 | 93 | Nota-se que muita gente costuma excluir caches de dependência, como o `node_modules`, arquivos de sistema, como o `.DS_Store`, entre diversos outros. 94 | 95 | Você pode ver o `.gitignore` [deste repositório](https://github.com/0nn0/git-basics-cheatsheet/blob/master/.gitignore) ou [mais exemplos](https://github.com/github/gitignore) do GitHub. 96 | 97 | ## Plataformas 98 | 99 | As plataformas abaixo são exemplos que podem ser usados para hospedar seus repositórios. 100 | 101 | | Plataforma | Preço | 102 | | ---------------------------------- | ------ | 103 | | [GitHub](https://github.com) | Grátis | 104 | | [GitLab](https://gitlab.com) | Grátis | 105 | | [Bitbucket](https://bitbucket.org) | Grátis | 106 | 107 | ## Cliente de Interface do Usuário (GUI) 108 | 109 | O terminal não é sua praia? Use um dos clientes abaixo. 110 | 111 | | Cliente | Sistema Operacional | Preço | 112 | | ------------------------------------------- | ------------------- | --------- | 113 | | [GitHub](https://desktop.github.com) | macOS e Windows | Grátis | 114 | | [Sourcetree](https://www.sourcetreeapp.com) | macOS e Windows | Grátis | 115 | | [Tower](https://www.git-tower.com) | macOS e Windows | $69 a $99 | 116 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | # Git Cheatsheet (Basics) 2 | 3 | This cheatsheet is a list of our most used Git commands, and it countains useful information for those who are getting started. 4 | 5 | It is available in the languages above. Since the translation rely on volunteers, the content between the available languages may vary. 6 | 7 | - [English Version](#english-version) 8 | - [Versão em Português](https://github.com/0nn0/git-basics-cheatsheet/tree/master/Português) 9 | 10 | _In case you've missed, there's a list of our most used commands and shortcuts in the [Terminal for macOS](https://github.com/0nn0/terminal-mac-cheatsheet)._ 11 | 12 | ## English Version 13 | 14 | ### Glossary 15 | 16 | | Keywords | Description | 17 | | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------- | 18 | | git | Open-source distributed version-control system, used to store code in repositories | 19 | | GitHub, GitLab and Bitbucket | Platform for hosting and collaborating on Git repositories | 20 | | staging | Proposed files/directories that you'd like to commit | 21 | | commit | Saving all staged files/directories to your local repository | 22 | | branch | An independent line of development, so you can develop features isolated from each other. Master branch is the default. | 23 | | clone | Local version of a repository, including all commits and branches | 24 | | remote | Common repository on eg. Github that all team members to keep that changes in sync with | 25 | | fork | Copy of a repository owned by a different user | 26 | | pull request | A method of submitting contributions to a repository | 27 | | HEAD | Represents your current working directory | 28 | 29 | ### Configuration 30 | 31 | | Key/Command | Description | 32 | | ---------------------------------------- | --------------------------------------------------- | 33 | | `git config --global user.name [name]` | Set author name to be used for all commits | 34 | | `git config --global user.email [email]` | Set author email to be used for all commits | 35 | | `git config color.ui true` | Enables helpful colorization of command line output | 36 | 37 | ### Core Commands 38 | 39 | | Key/Command | Description | 40 | | --------------------------- | -------------------------------------------------------- | 41 | | `git init [directory]` | Creates new local repository | 42 | | `git clone [repo]` | Creates local copy of remote repository | 43 | | `git add [directory]` | Stages specific [directory] | 44 | | `git add [file]` | Stages specific [file] | 45 | | `git add -A` | Stages all changed files | 46 | | `git add .` | Stages new and changed files, NOT deleted files | 47 | | `git add -u` | Stages changed and deleted files, NOT new files | 48 | | `git commit -m "[message]"` | Commit everything that is staged | 49 | | `git status` | Shows status of changes as untracked, modified or staged | 50 | 51 | ### Synchronization of Changes 52 | 53 | | Key/Command | Description | 54 | | ------------- | ------------------------------------------------------------------------------------- | 55 | | `git fetch` | Downloads all history from the remote branches | 56 | | `git merge` | Merges remote branch into current local branch | 57 | | `git pull` | Downloads all history from the remote branch and merges into the current local branch | 58 | | `git push` | Pushes all the commits from the current local branch to its remote equivalent | 59 | 60 | *Tip: `git pull` is the combination of `git fetch` and `git merge`* 61 | 62 | ### Undo Changes 63 | 64 | | Key/Command | Description | 65 | | --------------------------- | ------------------------------------------------------------------------------------------- | 66 | | `git checkout -- [file]` | Replace file with contents from HEAD | 67 | | `git revert [commit]` | Create new commit that undoes changes made in [commit], then apply it to the current branch | 68 | | `git reset [file]` | Remove [file] from staging area | 69 | | `git reset --hard HEAD` | Removes all local changes in working directory | 70 | | `git reset --hard [commit]` | Reset your HEAD pointer to previous commit and discard all changes since then | 71 | 72 | ### Branches 73 | 74 | | Key/Command | Description | 75 | | -------------------------- | ---------------------------------- | 76 | | `git branch [branch]` | Create a new branch | 77 | | `git checkout [branch]` | Switch to that branch | 78 | | `git checkout [branch] -b` | Create and checkout new branch | 79 | | `git merge [branch]` | Merge [branch] into current branch | 80 | | `git branch -d [branch]` | Deletes the [branch] | 81 | | `git push origin [branch]` | Push [branch] to remote | 82 | | `git branch` | Lists local branches | 83 | | `git branch -r` | Lists remote branches | 84 | | `git branch -a` | Lists local and remote branches | 85 | 86 | ### History 87 | 88 | | Key/Command | Description | 89 | | -------------------------- | ---------------------------------------------------------------- | 90 | | `git log` | Lists version history for the current branch | 91 | | `git log --author=[name]` | Lists version history for the current branch from certain author | 92 | | `git log --oneline` | Lists compressed version history for the current branch | 93 | | `git show [commit]` | Outputs metadata and content changes of the specified commit | 94 | | `git blame [file]` | Shows who changed what and when in file | 95 | 96 | ### Gitignore 97 | 98 | You can list files/directories that you want to explicitely exclude from Git in a `.gitignore` file. This file should be placed at the root of your repository. 99 | 100 | It is noted that people usually exclude dependency caches, such as `node_modules`, system files, such as `.DS_Store`, among others. 101 | 102 | You can see the `.gitignore` file of [this repository](https://github.com/0nn0/git-basics-cheatsheet/blob/master/.gitignore) or [more examples](https://github.com/github/gitignore) provided by GitHub. 103 | 104 | ### Platforms 105 | 106 | The following platforms can be used to host your repositories. 107 | 108 | | Platform | Price | 109 | | ---------------------------------- | ----- | 110 | | [GitHub](https://github.com) | Free | 111 | | [GitLab](https://gitlab.com) | Free | 112 | | [Bitbucket](https://bitbucket.org) | Free | 113 | 114 | ### Graphical User Interface (GUI) 115 | 116 | Is the command-line interface not for you? Try one of the following clients. 117 | 118 | | Clients | Operational System | Price | 119 | | -------------------------------------------- | ------------------ | ---------- | 120 | | [Github](https://desktop.github.com) | Mac and Windows | Free | 121 | | [Source Tree](https://www.sourcetreeapp.com) | Mac and Windows | Free | 122 | | [Tower](https://www.git-tower.com) | MacOS and Windows | $69 to $99 | 123 | 124 | ### Resources 125 | - [Learn Git concepts, not commands](https://dev.to/unseenwizzard/learn-git-concepts-not-commands-4gjc) 126 | - [Syncing a Fork](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/syncing-a-fork) 127 | - [Flight rules for Git](https://github.com/k88hudson/git-flight-rules) - What to do when things go wrong... 128 | - [*Pro Git*](https://book.git-scm.com/book/en/v2) 129 | - [Git Flow](https://guides.github.com/introduction/flow/) 130 | - [Git and Github in Plain English](https://blog.red-badger.com/2016/11/29/gitgithub-in-plain-english) 131 | - [Learn Git Version Control using Interactive Browser-Based Scenarios](https://www.katacoda.com/courses/git) 132 | --------------------------------------------------------------------------------