Gerar SSH Key GitLab
$ ssh-keygen -t rsa -b 2048 -C "GitLab"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/alexandro/.ssh/id_rsa): <Press_Enter>
Enter passphrase (empty for no passphrase): <Insert_passphrase>
Enter same passphrase again: <Insert_passphrase>
Your identification has been saved in /home/alexandro/.ssh/id_rsa
Your public key has been saved in /home/alexandro/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:FCUhodrCD5Dw1Bxl5+wP1GBFsy8uEYm5CpgdRAzpQ3Y GitLab
The key's randomart image is:
+---[RSA 2048]----+
|o=+o.o=.D== |
|oB.Eoo O * o |
|* + . o . o |
| O + = . . |
|o O D . S . . |
| = . = . |
| o . o |
| . |
| |
+----[SHA256]-----+
$ mv /home/alexandro/.ssh/id_rsa /home/user/.ssh/gitlab
$ mv /home/alexandro/.ssh/id_rsa.pub /home/user/.ssh/gitlab.pub
$ vi /home/alexandro/.ssh/config
# GitLab.com
Host gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitlab
Link: 1
Acesse o GitHub account e clique em Settings > Developer settings > Personal access tokens > Generate New Token > Insert password
Adicionar uma nota
Escolher a data de expiração do token
Selecione os "scopes"
Confirme e salve o token em outro local
Crie o repositório no GitLab ou GitHub através da interface Web
Realize o clone do repositório em um local de seu computador
$ git clone https://gitlab.com/<username>/<repositorio>.git
OU
$ git clone https://github.com/<username>/<repositorio>.git
Configurar variáveis globais
$ git config --list
$ git config --global user.name "<username>"
$ git config --global user.email "<email>"
$ git config --global color.ui true
Para realizar push, ao alterar algum conteúdo utilize os comandos abaixo para atualizar o repositório no GitLab/GitHub.
$ git add .
$ git commit -m "1st"
$ git push origin
Nota: para enviar ao GitHub é necessário gerar token de segurança e então no lugar da senha sera usado o token.
…or create a new repository on the command line
echo "# Repositorio" >> README.md
$ git init
$ git add --all
$ git add README.md
$ git commit -m "first commit"
$ git branch -M main
$ git remote add origin https://(gitlab|github).com/<username>/<repositorio>.git <- Escolher Lab ou Hub
$ git push -u origin main
…or push an existing repository from the command line
$ git remote add origin https://(gitlab|github).com/<username>/<repositorio>.git <- Escolher Lab ou Hub
$ git branch -M main
$ git push -u origin main
Caso apresente a mensagem abaixo ao executar o comendo
# git pull
error: Your local changes to the following files would be overwritten by merge:
....
Please commit your changes or stash them before you merge.
Aborting
Execute os comandos abaixo para correção
# git fetch --all
Fetching origin
# git reset --hard origin/master
Checking out files: 100% (1344/1344), done.
HEAD is now at e3e02f63 2.1.27
# git pull