├── CONTRIBUTING.eng.md ├── CONTRIBUTING.md ├── README.eng.md ├── README.md ├── git-flow.md ├── interactive-rebase.eng.md ├── patterns-git.eng.md ├── patterns-git.md └── rebase-interativo.md /CONTRIBUTING.eng.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | ## Welcome 4 | 5 | ### You can contribute in the following ways: 6 | - Adding new git commands or concepts or tools 7 | 8 | ### Thank you for want to help to contribute to this project! :octocat: 9 | 10 | - Fork this repo on GitHub. 11 | - Clone the forked repository to your local system. 12 | - `git clone https://github.com/`YOUR_USERNAME`/git-commands.git` 13 | - Make another branch. 14 | - `git checkout -b `NAME_OF_YOUR_BRANCH`` 15 | - Make the new changes and, when finished, make: 16 | - `git add .` 17 | - `git commit -m "`YOUR_COMMIT_MESSAGE`"` 18 | - `git push origin `NAME_OF_YOUR_BRANCH`` 19 | - Open a pull request on GitHub for this repo. 20 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribuindo 2 | 3 | ## Bem-vinde 4 | 5 | ### Você pode contribuir das seguintes formas: 6 | - Adicionando novos comandos/conceitos/ferramentas do git 7 | - Ajudando a traduzir os comandos/conceitos/ferramentas já existentes para o inglês, confira: [Do you speak English?](README.eng.md) 8 | 9 | ### Obrigada pela sua ajuda em contribuir com esse projeto! :octocat: 10 | 11 | - Faça o Fork do repositório no GitHub. 12 | - Clone o repositório forkado para sua máquina local. 13 | - `git clone https://github.com/`SEU_USERNAME`/git-commands.git` 14 | - Crie uma nova branch. 15 | - `git checkout -b `NOME_DA_SUA_BRANCH`` 16 | - Faça suas alterações e ao finalizar: 17 | - `git add .` 18 | - `git commit -m "`SUA_MENSAGEM_DO_COMMIT`"` 19 | - `git push origin `NOME_DA_SUA_BRANCH`` 20 | - Abra um pull request no GitHub para este repositório. 21 | -------------------------------------------------------------------------------- /README.eng.md: -------------------------------------------------------------------------------- 1 | # 📓 GIT COMMANDS 2 | 3 | - [How to contribute?](CONTRIBUTING.eng.md) 4 | 5 | ## Summary 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 |
CommandsHow it works?
git addAdd files on stagging to prepare for the next commit
git status logView the status of your changes
git commitRecord changes to the repo and given log message describing the changes
git pushUpdate remote repo with their local changes
git pullTo download information from the remote repo to the local repo
git fetchUpdate refs
git branch/checkoutList, create, delete and switch branches
git mv/rmMove, rename or remove files from the working tree and from the index
git mergeMerge between remote or local branches
git rebaseReapply commits on top of another base tip
git revertRevert some existing commits
git resetReset current HEAD to the specified state
othersMore useful git commands
65 | 66 |

Danger levels of Commands

67 | 72 | 73 | ## Other concepts: 74 | - [Git flow](git-flow.eng.md) 75 | - [Patterns git](patterns-git.eng.md) 76 | - [Interactive rebase](interactive-rebase.eng.md) 77 | 78 |

git add - Add files on stagging to prepare for the next commit

79 | 80 | 84 | 85 |

git status/log - View the status of your changes

86 | 87 | 96 | `git log --pretty=oneline` - shows the history of commits in a single per commit with the full hash.
97 | 98 |

git commit - Record changes to the repo and given log message describing the changes

99 | 100 | 103 | 104 |

git push - Update remote repo with their local changes

105 | 106 | 112 | 113 |

git pull - To download information from the remote repo to the local repo

114 | 115 | 119 | 120 |

git fetch - Update refs

121 | 122 | 124 | 125 |

git branch/checkout - List, create, delete and switch branches

126 | 127 | 138 | 139 |

git mv/rm - Move, rename or remove files from the working tree and from the index

140 | 141 | 146 | 147 |

git merge - Merge between remote or local branches

148 | 149 | 152 | 153 |

git rebase - Reapply commits on top of another base tip

154 | 155 | 157 | 158 |

git revert - Revert some existing commits

159 | 160 | 162 | 163 |

git reset - Reset current HEAD to the specified state

164 | 165 | 170 | 171 |

Others - More useful git commands

172 | 173 | 177 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 📓 GIT COMMANDS 2 | 3 | - [Como contribuir?](CONTRIBUTING.md) 4 | - [Do you speak English?](README.eng.md) 5 | 6 | ## Tópicos 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
ComandosO que faz?
git addColocar arquivos na fase de stagging
git status logVer o status das suas alterações
git commitManipular alterações pós stagging
git pushEnviar alterações para o repositório remoto
git pullBaixar informações do repositório remoto para o local
git fetchAtualizar referências
git branch/checkoutManipulação de branches e navegação entre branches
git mv/rmTrabalhando com arquivos e diretórios
git mergeFazendo merge entre branches
git rebaseReaplica commits em cima de determinada branch ou commit
git revertComo desfazer alterações
git resetReseta o HEAD atual para o estado especificado
outrosMais comandos úteis
66 | 67 |

Nível de Perigo de Comandos

68 | 73 | 74 | ## Outros conceitos: 75 | - [Git flow](git-flow.md) 76 | - [Patterns git](patterns-git.md) 77 | - [Rebase interativo](rebase-interativo.md) 78 | 79 |

git add - Colocar arquivos na fase de stagging - (Atenção)

80 | 81 | `git add . ` - adiciona todas alterações feitas na fase de stagging.
82 | `git add file.txt` - adiciona file.txt na fase de stagging.
83 | `git add *.js` - adiciona todos arquivos com a extensão .js para fase de stagging, para saber mais como selecionar vários arquivos de uma só vez de uma olhada em [wildcards](https://www.tecmint.com/use-wildcards-to-match-filenames-in-linux/).
84 | `git add --patch` - vejo linha por linha da alteração e consigo selecionar o que quero adicionar ao commit.
85 | 86 |

git status/log - Ver o estado das suas alterações - (Inofensivo)

87 | 88 | `git status` - vê estado dos commits.
89 | `git status -s` - status resumido.
90 | `git status --short` - status resumido.
91 | `git log` - mostra lista de commits.
92 | `git log --oneline` - mostra historico de commits em uma linha por commit.
93 | `git log --abbrev-commit` - mostra historico de commits em uma linha por commit.
94 | `git log --color` - mostra historico de commits e tenta colorir o output.
95 | `git log --graph` - mostra historico em um grafico das branchs em modo texto.
96 | `git log --pretty` - mostra historico e permite que sejam utilizados place holders para as informações dos commits.
97 | `git log --pretty=oneline` - mostra o histórico de commits em uma linha por commit com o hash completo.
98 | 99 |

git commit - Manipular alterações pós stagging - (Atenção)

100 | 101 | `git commit -a` - commit direto, sem passar por stagging.
102 | `git commit -m "Mensagem"` - commit passando pelo stagging com mensagem de alteração.
103 | `git commit --amend` - adiciona alterações no commit anterior.
104 | 105 |

git push - Enviar alterações para o repositório remoto - (Atenção)

106 | 107 | `git push origin master` - envia as alterações para o repositório na branch master.
108 | `git push` - envia as alterações para o repositório na branch em que você está.
109 | `git push --set-upstream origin new-branch` - faz push da nova branch e suas alterações.
110 | `git push -u origin ` - faz push da branch (nova ou não) e suas alterações.
111 | `git push --delete origin ` - remove do repositório online a branch desejada.
112 | `git push origin --tags` - além do push normal eu preciso fazer push das tags também, para acrescentar uma tag no que foi commitado.
113 | 114 |

git pull - Baixar informações do repositório remoto para o local - (Atenção)

115 | 116 | `git pull origin` - baixa commits do repositório remoto.
117 | `git pull` - baixa commits do repositório remoto (igual o de cima).
118 | `git pull --rebase` - força rebase ao fazer pull.
119 | `git pull origin master --allow-unrelated-histories` - Vai permitir que juntes dois repositórios com históricos de commits diferentes, exemplo: quando vc cria um novo repositório no Github e tem os arquivos README.md, LICENSE e no seu laptop existe já um repositório local com mais ficheiros e pretendes subir este repositório local para o Github, primeiro tens de juntar o repositório que está no Github com teu repositório local e sendo eles repositórios com históricos de commits diferentes vc precisa especificar a opção --allow-unrelated-histories quando fazer o git pull.
120 | 121 |

git fetch - Atualizar referências - (Atenção)

122 | 123 | `git fetch origin` - atualiza as referências com um repositório remoto (busca branches etc).
124 | `git fetch` atualiza as referências com um repositório remoto (busca branches etc) ||.
125 | 126 |

git branch/checkout - Manipulação de branches e navegação entre branches - (Atenção)

127 | 128 | `git branch ` - cria nova branch com o nome desejado.
129 | `git branch` - lista as branches disponíveis no repositório local.
130 | `git branch -d ` - remove branch do repositorio local.
131 | `git checkout ` - navega para aquela branch.
132 | `git checkout -b ` - cria nova branch e já faz checkout nela.
133 | `git checkout -` - o git checkout - te leva a branch que você estava trabalhando antes de trocar de branch.
134 | `git checkout HEAD~2` - move o HEAD para dois commits anteriores.
135 | `git checkout -- ` - recupera diretamente no working dir o arquivo desejado.
136 | `git checkout --ours ` - adiciona conteúdo sem modificação que conflitou.
137 | `git checkout --theirs` - adiciona conteúdo em conflito na branch atual que estou.
138 | `git checkout ` - "travo" para usar aquele commit em específico.
139 | 140 |

git mv/rm - Trabalhando com arquivos e diretórios - (Perigoso)

141 | 142 | `git mv ` - renomeia um arquivo com um nome para um novo nome.
143 | `git mv ... ` - move o arquivo_1, arquivo_2, arquivo_3 e mais outros para o diretório de destino. *Nota:* vc pode estudar sobre [wildcards](https://www.tecmint.com/use-wildcards-to-match-filenames-in-linux/) para conseguir selecionar um conjunto de arquivos sem a necessidade de escrever o nome de cada um deles. *Exemplo:* `git mv *.js SCRIPTS-JS/` esse comando vai copiar todos arquivos com a extensão **.js** para o diretório SCRIPTS-JS/.
144 | `git rm ` - remove determinado arquivo do repositório local. *Nota:* vc pode eliminar mais do que um arquivo e podes também usar [wildcards](https://www.tecmint.com/use-wildcards-to-match-filenames-in-linux/) .
145 | `git rm -r ` - remove determinado todo diretório com seus arquivos e subdiretórios.
146 | `git rm -r *` - Elimina todos os arquivos e subdiretórios apartir da sua localização actual quando executar este comando.
147 | 148 |

git merge - Fazendo merge entre branches - (Atenção)

149 | 150 | `git merge ` - faz merge com a branch desejada.
151 | `git merge -no-ff` - faz merge com a branch deseja no modo 3-way.
152 | `git merge -abort` - cancela um merge que eu havia feito.
153 | 154 |

git rebase - Reaplica commits em cima de determinada branch ou commit - (Atenção)

155 | 156 | `git rebase ` - reaplica todos os commits na branch desejada.
157 | `git rebase master -i` - mostra lista de commits e posso alterar ela para mudar o histórico e tudo, muito foda.
158 | 159 |

git revert - Como desfazer alterações - (Perigoso)

160 | 161 | `git revert ` - reverte as alterações de um commit específico e cria um novo commit.
162 | `git revert` - não modifica histórico de commits, mas cria um novo commit com o inverso do commit desejado, ou seja, o resultado final é o commit anterior.
163 | 164 |

git reset - Reseta o HEAD atual para o estado especificado - (Perigoso)

165 | 166 | `git reset HEAD~1 --hard` - descarta e elimina as alterações do último commit.
167 | `git reset HEAD~2 ` - restaura para o staging as alterações do arquivo desejado em dois commits atrás.
168 | `git reset --mixed` - altera o staging e o repositório, mantém o working dir intacto. É o padrão e é útil nos casos que queremos desfazer partes das alterações e criar um novo commit em seguida.
169 | `git reset --soft` - similar ao mixed, mas mantém o staging como está.
170 | `git reset --hard` - desfaz tudo a partir de um commit específico.
171 | 172 |

Outros - Mais comandos úteis do git

173 | 174 | `git tag ` - cria uma tag com a versao desejada.
175 | `git clone --depth` - quero o clone a partir de X commits.
176 | `git clean -f` - remove untracked files
177 | `git remote add origin ` - Faz uma ligação com o seu repositório remoto e essa ligação será chamada *origin* note que o nome da ligação pode ser alterado e não ser necessariamente *origin*.
178 | `git commit --author="Ms. Jane Codeldoe " -m "Jane wrote this I'm just committing"` - Muda o autor de um determinado commit 179 | -------------------------------------------------------------------------------- /git-flow.md: -------------------------------------------------------------------------------- 1 | # GIT FLOW 2 | 3 | git flow init - inicia um projeto git com gitflow 4 | git flow feature start - cria uma branch de feature com o nome da feature desejada 5 | git flow feature publish - faz push das features no git 6 | git flow feature finish - finalizo as features e faz merge com develop e deleta branch (local e online) 7 | git flow release start - cria release 8 | git flow release finish - finalizo a release e deleta branch (local e online) = abre varias janelas para adicionar nome da release, tag, etc 9 | 10 | --> Importante após finalizar as coisas fazer push das branches que ainda estão "em aberto" e fazer push das tags e release -------------------------------------------------------------------------------- /interactive-rebase.eng.md: -------------------------------------------------------------------------------- 1 | # INTERACTIVE REBASE 2 | 3 | p, pick: use commit 4 | r, reword: use commit, but edit the commit message 5 | e, edit: use commit, but stop for amending 6 | s, squash: use commit, but meld into previous commit 7 | f, fixup: like "squash", but discard this commit's log message 8 | x, exec: run command (the rest of the line) using shell 9 | d, drop: remove commit -------------------------------------------------------------------------------- /patterns-git.eng.md: -------------------------------------------------------------------------------- 1 | # PATTERNS 2 | 3 | \# - The hash marks a comment in our archive 4 | * - Ignores parts of a pattern's name, acting like a wildcard 5 | ! - Allows a specific pattern to be excluded. Usually comes with a more general rule 6 | / - It has different functions depending on your location. At the beginning of the line, ignore a pattern in that directory only, but not in its subdirectories. In the end, it ignores the entire directory tree 7 | \ - Escape character 8 | ** - Two asterisks are then used to ignore a specific pattern within a directory tree 9 | 10 | Examples: 11 | >Ignore all html files in the repository 12 | *.html 13 | 14 | >Except the index.html file 15 | !index.html 16 | 17 | >Ignore README in the current directory, but allow subdir/README 18 | /README 19 | 20 | >Ignore all files in the build/ directory 21 | build/ 22 | 23 | >Ignore .txt files in the doc/ directory, but allows subdirectories (doc/server/arch.txt) 24 | doc/*.txt 25 | 26 | >Ignore all .pdf files in the doc/ tree 27 | doc/**/*.pdf -------------------------------------------------------------------------------- /patterns-git.md: -------------------------------------------------------------------------------- 1 | # PATTERNS 2 | 3 | \# - A cerquilha marca um comentário em nosso arquivo 4 | * - Ignora partes do nome de um pattern, agindo como um coringa 5 | ! - Permite que um determinado pattern seja excluído. Geralmente vem acompanhado de outra regra mais genérica 6 | / - Tem função diferente dependendo da sua localização. No início da linha, ignora um pattern somente naquele diretório, mas não em seus subdiretórios. No final ignora toda a árvore do diretório 7 | \ - A barra invertida atua como um caractere de escape 8 | ** - Dois asteriscos em seguida são usados para ignorar um pattern específico dentro de uma árvore de diretórios 9 | 10 | Exemplos com patterns: 11 | >Ignora todos os arquivos html do repositório 12 | *.html 13 | 14 | >Exceto do arquivo index.html 15 | !index.html 16 | 17 | >Ignora o README no diretório atual, mas permite subdir/README 18 | /README 19 | 20 | >Ignora todos os arquivos no diretório build/ 21 | build/ 22 | 23 | >Ignora os arquivos .txt do diretório doc/, mas permite subdiretórios (doc/server/arch.txt) 24 | doc/*.txt 25 | 26 | >Ignora todos arquivos .pdf na árvore doc/ 27 | doc/**/*.pdf -------------------------------------------------------------------------------- /rebase-interativo.md: -------------------------------------------------------------------------------- 1 | # REBASE INTERATIVO 2 | 3 | p, pick: usa o commit daquela linha 4 | r, reword: usa o commit e permite a edição da sua mensagem 5 | e, edit: usa commit, fazendo uma pausa para adicionar mais alterações (--amend) 6 | s, squash: usa as alterações do commit, juntando ela com o commit anterior 7 | f, fixup: parecido com squash, porém desconsidera a mensagem de log do commit 8 | x, exec: executa um comando na linha de comando (útil para automatizações) 9 | d, drop: remove o commit --------------------------------------------------------------------------------