![]() If it's public, it's available to everyone. I can add a description if I want to, and I can choose if I want this repository to be public or private. For this, I will just call it git-repo, which is short for repository. First, we need to decide on the repository name, this will be part of the URL, so it's best to not use spaces. Once we click that, we have a few options to fill in. Once your account is ready, you have the option in the web interface to create a new repository. It's completely free to do so, you just need an email address. If you see in the upper right corner, there is a link where you can sign up. If you don't have an account yet, you can go to. For this example, we are going to use GitHub. The good thing is that although interfaces might be a bit different, they all use the same concepts, so if you know how one of them works, you know how to use the other ones. There are a few different providers that you can use like GitHub or GitLab or Bitbucket. Because it's in the cloud, you can use it as a source to pull code to other computers. This is a web service in the cloud where you can store a Git repository like you would do locally. For a remote repository, we use a Git provider. In this section, we are going to create a remote repository so that we have something to practice with when we use Git. To :john/newsletter.git 2b35421.- With our device completely ready, let's push our first code. Total 3 (delta 2), reused 0 (delta 0), pack-reused 0 remote: Resolving deltas: 100% (2/2), completed with 2 local objects. Delta compression using up to 4 threads Compressing objects: 100% (3/3), done. remote: Already on 'main' To :/home/john/newsletter 2b35421.aa80729 main -> main Enumerating objects: 5, done. Total 3 (delta 2), reused 0 (delta 0), pack-reused 0 remote: Push received! Deploying branch: main. On your local machine, run git push origin main: $ git push origin main Enumerating objects: 5, done. The post-receive file mode should have -rwxrwxr-x. ![]() We need to make the file executable: # chmod +x post-receive # $ ls -Al ~/newsletter/hooks total 56 -rwxrwxr-x 1 shin shin 478 Apr 24 03:07 applypatch-msg.sample -rwxrwxr-x 1 shin shin 896 Apr 24 03:07 commit-msg.sample -rwxrwxr-x 1 shin shin 3079 Apr 24 03:07 fsmonitor-watchman.sample -rwxrwxr-x 1 shin shin 732 May 3 00:58 post-receive -rwxrwxr-x 1 shin shin 189 Apr 24 03:07 post-update.sample -rwxrwxr-x 1 shin shin 424 Apr 24 03:07 pre-applypatch.sample. # cd ~/newsletter/hooks # touch post-receive On your remote server, create a file ~/newsletter/hooks/post-receive. Now you should have one fetch and two pushes: $ git remote -v origin john/newsletter.git (fetch) origin john/newslette (push) origin john/newsletter.git (push) Step-3 Create a post-receive file You need to run git remote set-url twice as above since the first one will overwrite the current one. $ git remote set-url -add -push origin john :/home/ john/newsletter $ git remote set-url -add -push origin john/newsletter.git One for our remote server and one for our Github repo. Using git remote set-url allows you to set multiple Git repo URLs.įind out your current remote config using the git remote -v command: $ git remote -v origin john/newsletter.git (fetch) origin john/newsletter.git (push) var/www/newsletter/public_htmlĬreate a new directory under /var/# sudo mkdir /var/www/newsletter/public_html Step-2 Setting multiple remote URLs on a local Gitrepo This will omit the working directory but create the directories and files we need. ![]() Initialize an empty Git repository in a new directory: # git init -bare Let’s connect to your server: $ ssh // or use your IP address $ ssh you are in the remote server, create a new directory, newsletter: # pwd /home/john # mkdir newsletter # cd newsletter You can connect to your server using SSH. I assume you secured your server and set firewalls on your server. Step-1 Creating working directories on a remote server /home/john/newsletter You have a Linux server for your website (I use Ubuntu 20.04) and you can use ssh to connect from your local computer to your remote server. ![]() You already have a working Git repository on your local machine. Also for simplicity, I use john for username and Github username, and for our domain name. ![]() I use $ for a local terminal prompt and # for a remote server prompt. In this article, you will learn how to create a post-receive Git hook that executes when you use the git push command. Setting up a Git hook makes your development and deployment easy. Git hooks are scripts that Git executes before or after commit, push, and receive. Photo by Tim Mossholder on Unsplash Introduction ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |