Last active
October 4, 2024 19:35
-
-
Save joulgs/705e081b5e16b210b003e5860eec5bb7 to your computer and use it in GitHub Desktop.
Configurar git remote num servidor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Criar e entrar no repositorio .git | |
mkdir ~/git/meu_projeto.git | |
cd ~/git/meu_projeto.git | |
# Iniciar um novo repositorio git bare | |
git init --bare | |
# Com o repositorio criado voce navega até hooks e criar um arquivo post-receive | |
cd hooks | |
touch post-receive | |
vim post-receive | |
#Escreva a seguinte configuração no arquivo post-receive: | |
#!/bin/bash | |
git --work-tree=/home/user/path/to/project --git-dir=/home/user/path/to/repositorio.git checkout -f | |
#salve o arquivo e der permissão de execução nele: | |
chmod +x post-receive | |
#prepare a pasta que vai receber o projeto, normalmente em /var/www/dominio.do.projeto | |
mkdir /var/www/dominio.do.projeto | |
#de permissão para o git funcionar | |
sudo chown user:www-data dominio.do.projeto/ -R | |
#agora é so voce adicionar o novo repositorio como remote no seu projeto | |
git remote add nome_origin user@servidor:/home/user/path/to/repositorio.git | |
# seta o ramo principal no servidor remoto como main | |
git push --set-upstream nome_origin main | |
git push -u nome_origin main | |
#agora voce pode subir branches para o servidor direto pelo git com: | |
git push nome_origin | |
ou o comando abaixo caso o ramo no servidor não seja o main: | |
git push nome_origin main:master | |
referencias: | |
- [1](https://medium.com/agits/deploy-com-git-configurando-e-executando-um-deploy-automatizado-156e3e1bc374) | |
- [2](https://tableless.com.br/deploy-usando-git-pull-e-hooks/) | |
- [3](https://www.akitaonrails.com/2010/02/13/deploy-com-git-push) | |
-- transformar um site em um repositorio remoto -- | |
1º crie um repositorio bare no servidor e crie o post-receive | |
git init --bare | |
2º inicie um repositorio git no site | |
git init | |
3º adicione o repositorio git bare como um remoto | |
git remote add origin pasta/com/repositorio/git.git | |
4º sincronizer o site com o repositorio bare | |
git add . | |
git commit -m "Primeiro Commit" | |
git push -u origin master | |
5º apague a instalação .git no site | |
6º configure o HEAD como main no repositorio bare | |
7º adicione o repositorio bare no seu local de trabalho e faça o pull | |
referencias | |
https://cursos.alura.com.br/forum/topico-transforma-projetos-locais-em-repositorios-git-45197 | |
https://www.treinaweb.com.br/blog/comandos-do-git-que-voce-precisa-conhecer-parte-2-repositorios-remotos | |
http://rogerdudler.github.io/git-guide/index.pt_BR.html | |
============ | |
# defina todos os novos repositorios com o branch inicial como main | |
git config --global init.defaultBranch main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment