How to set a central repository in Git
Background story
TODO ?
Getting started
In the folder you want your central repository run :
In the folder where you will make a local copy or the central repository and start working, run this command :
Basically, this will make a ssh connection with the server and apply the git command which is git clone
in that case.
And you're good to go !
Command on the bare repository
When you commit a lot of changed in your central repository and you're happy about the historic, you can run the following command:
Setting up the client repository
Since you make an ssh connection every time you execute a git command, you will enter your server password a lot of times, aka
If you're fine with that, don't bother with this section. But if you find it annoying you can solve it.
Share a passphrase with the server
In order to avoid entering your password, you will have to generate a passphrase. But if you do not have one yet, this can be done using the following command.
Follow the prompted instructions it's recommanded to use a passphrase and not leave it empty.
Once you've done it, you have to share it with the server. You can do that with :
You will have to enter your password in order to log in the server. You can then log in the server and check the authorized_keys to see if the new one is added :
Use ssh-agent
to store the passphrase for us
ssh-agent
to store the passphrase for usIf you entered a passphrase in the ssh-keygen
step, you should have the same problem that before. But instead of a password, it's now a passphrase that is required !
So we did not went far on our problem.
But luckily for us, there is a deamon that can helps us with passphrase : ssh-agent
You can make sure your agent is running with (it will start it it if not already running) :
You only have to run the following command :
It will prompt you to enter your passphrase. And just like with the password, you're done ! 🎉
You can make a test and run ssh '<username>@<server-address>''
to test if it works.
You should, in theory, not have to enter any passwords or passphrase !
Note: You can also run the below commands to make sure the ssh-agent
has the right identities:
Remove a ssh key added
You might have add a ssh key that wasn't the one you wanted to use for that server. To fix your mistake, you can remove the desired key in the file known_hosts
and authorized_keys
with:
Useful commands
You can check information about the remote url you can run the following command
You have a lot of control on the
ssh-agent
. You can for example specify the lifetime of identities it hold with
Using Fork
This can be also be accomplished quite easily with Fork git client. All you have to do is : 1. File
> Configure SSH Keys...
2. In the dropdown menu, select the keys you want to use for this repository. You can also generate a new one if you wish. 3. When making a server command, you will have a prompt to emter your passphrase. 4. Once enter, you should be able to make other server commands without worrying about it again.
Aknowledgements
Last updated
Was this helpful?