-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTutorial GIT.txt
165 lines (132 loc) · 4.5 KB
/
Tutorial GIT.txt
1
2
3
4
5
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
INSTALAÇÃO E CONFIGURAÇÃO
INSTALAR
$ sudo apt install git
CONFIGURAR SSH
Tutorial: https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/
VER SE TEM CHAVE SSH
$ ls -a ~/.ssh
GERAR SSH (substituir "[label]" por um rótulo personalizado)
$ ssh-keygen -t rsa -b 4096 -C "[label]"
ENTER para caminho default
Inserir passphrase
CONFIGURAR SSH
$ eval "$(ssh-agent -s)"
$ ssh-add ~/.ssh/id_rsa
ADICIONAR CHAVE À CONTA
Entrar em https://github.com/settings/keys
> New SSH Key
Dar um título
Copiar chave (em ~/.ssh/id_rsa.pub)
CONFIGURAR
VERIFICAR CONFIGURAÇÕES
$ git config --list
EDITOR (substituir "[editor]" pela comando para o seu editor)
$ git config --global core.editor [editor]
IDENTIDADE
$ git config --global user.email "[email protected]"
$ git config --global user.name "Your Name"
SIMPLIFICAR PUSH
$ git config --global push.default matching
PREPARAR WORKING DIRECTORY
Criar uma pasta e iniciar o terminal a partir dela
ACESSAR REPOSITÓRIO
(VAI PRECISAR ESTAR COM PERMISSÃO DE ACESSO AO REPOSITÓRIO)
$ git clone ssh://[email protected]/llucasll/BubbleShooter.git
$ cd BubbleShooter/
COMEÇAR UM REPOSITÓRIO
//criar commit localmente e no GitHub, e então
git config user.email --
git config user.name --
git add .; git commit -m "Primeiro commit"
git remote add origin --
git branch --set-upstream-to=origin/master
git pull --allow-unrelated-histories
git push
//
PARA CADA NOVO BRANCH, CONFIGURAR
$ git branch --set-upstream-to=origin/[branch]
# A forma completa permite linkar qualquer branch local com o servidor (não apenas o que você está no momento)
$ git branch --set-upstream-to=origin/[branch] [branch]
BÁSICO
VERIFICAR SE EXISTEM MODIFICAÇÕES LOCAIS (NO WORKING DIRECTORY)
(em comparação ao último commit local)
$ git status
DOWNLOAD
$ git pull
UPLOAD - CAMINHO ULTRAFÁCIL
$ git add .; git commit -m "Update"; git push
UTILÍSSIMO
$ find ./ -type f -exec grep -l -i "TODO" {} \;
# Procura em todos os arquivos na pasta atual (./) pela string TODO
//
UPLOAD - CAMINHO FÁCIL (TORTUOSO)
$ git commit -am "Update"
Means "All, with Message.."
Essa opção não inclui novos arquivos. Para incluí-los, executar manualmente
$ git add .
$ git push
UPLOAD - OUTRO CAMINHO
$ git add .
Ou $ git add *
Não usar essa opção pq pelo visto ela não abrange arquivos ocultos (iniciados com .)
Ou $ git add -A
Se quiser recomeçar
$ git reset
$ git commit -m "[Título]"
$ git push
Ou $ git push origin master
AVANÇADO
EXIBIR
$ git branch -a # All, mostra remotos tbm
$ git tag
$ gitk
Antes, instalar
$ sudo apt install gitk
$ git diff --color=always | less -r
$ git show # mostra as modificações do último commit por extenso, como no GitHub
$ git log # mostra a lista de commits a partir de HEAD
COMPARAR VERSÕES DE UM ARQUIVO
$ git diff [COMMIT/BRANCH/TAG a] [COMMIT/BRANCH/TAG b] -- [ARQUIVO]
VOLTAR [N] COMMITS
$ git reset HEAD~[N] --hard
$ git push --force
RENOMEAR BRANCH
#rename the local branch to the new name
$ git branch -m old_name new_name
# -m == --move
#delete the old branch on remote - where <remote> is eg. origin
$ git push <remote> --delete old_name
#push the new branch to remote
$ git push <remote> new_name
MOVER BRANCH (FAZER APONTAR PARA OUTRO COMMIT)
$ git branch -f [BRANCH] [NOVA POSIÇÃO]
EXCLUIR BRANCH
LOCALMENTE
$ git branch -d [BRANCH]
REMOTAMENTE
$ git push origin :[BRANCH]
TUTORIAL PRA CONVERTER BRANCH EM TAG
CRIAR TAG
$ git checkout [BRANCH]
$ git tag -a [TAG NAME] -m '[MESSAGE]'
$ git checkout master
APAGAR BRANCH
$ git branch -d [BRANCH]
$ git push origin :[BRANCH]
ENVIAR ATUALIZAÇÕES
$ git push origin --tags
$ git push
OUTROS
VERIFICAR POR MODIFICAÇÕES LOCAIS (WD)
$ git diff [BRANCH]
DESCARTAR MODIFICAÇÕES LOCAIS (MUITO ÚTIL NO CASO DE UM MERGE QUE DEU ERRADO)
$ git reset --hard
# descarta o trabalho no WD e retorna ao commit para o qual HEAD aponta
# mas apenas para os arquivos que já existiam previamente
$ git clean -d -f
# Clean unknown files from the working tree
# Força a exclusão, inclusive de Diretórios.
DESCARTAR VERSÃO LOCAL E FORÇAR SOBRESCREVER COM A REMOTA
$ git reset --hard origin/master
$ git fetch # atualizar referências locais às remotas, sem interferir nos branches locais
$ git log --color=always | less -r