How to connect to server using Git and Github

660 0 0 0

Last Updated : 2024-03-28 18:25:10

In this snippet I will explain how to create connection between local git, github and remote server

In this snippet I will explain how to create connection between local git, github and remote server .


First Stage: Local 


1- in your computer -> go to desktop -> right click -> choose gitbash here -> write ssh-keygen -> enter -> put a passphrase or not (its optional)


2- step 1 will create ssh file for you in this path C: \ users \ your_user \ .ssh \ id_rsa.pub 


3- open this file with any text editor -> it will contain a long text (key) -> copy this key .


Second Stage: Github


4- after creating local ssh file -> go to github -> got to profile -> click on profile avatar -> choose settings -> from left side pabel -> choose SSH and GPG keys -> add  new SSH key -> type any title you want and paste the key generated from step 3


Third Stage: server


5- open your server -> login with your account and password -> go to security -> choose SSH Access -> open manage SSH keys -> generate new SSH Key 


6- after generating new SSH key in the server -> the key will be have 2 keys (public and private key) -> open the public key -> copy it 


7- now it's time to link the github repo with the server -> So from the step 6 you get the public key from the server -> go to the github Repository you want to link with the server -> go to settings (in the repo itself not the public account) -> from left side menu -> open deploy keys -> add new deploy key -> provide any title you want and paste the key generated from the SSh on the server.


Now the link between the github repo and the server is connected successfully.


Fourth Stage: Git on server


8- after all the steps above you have to create a git repo on the server itself -> using git init on the server terminal -> then all git commands will be available to you 


 


Note


in the server terminal -> if you pull from github and you face a warning or something like that -> you can make a new branch on the server -> pull to it -> then merge to the master again 

Mahmoud Anwar

Mahmoud Anwar

Back End Developer with a passion for developing innovative web applications that expedite the efficiency and effectiveness of organizational success. Well-versed in technology and writing code to create systems that are reliable and user-friendly. Also has the proven ability to motivate, educate, and collaborate effectively to build web applications and effectively track changes. Confident communicator, strategic thinker, and innovative creator to develop software that is customized to meet a company’s organizational needs, highlight their core competencies, and further their success.