Some days ago, for some reason, a remote repository needs to be created on Windows.
Gitstack is used directly because it is too troublesome and time-consuming.
I found that this item actually requires payment. I can only create two users without authentication.
It is enough for me, but it is not a long-term plan.
Fortunately, another machine was installed with Linux, Which is back on track.
This is because I have been using a remote repository created by others. This time, I will record the creation process.
Git init is the first step. I often take the following operations for granted:
123456789101112 |
[[email protected] ~] # mkdir myProject [[email protected] ~] # cd myProject/ [[email protected] myProject] # git init Initialized empty Git repository in /root/myProject/ .git/ [[email protected] myProject] # touch myProject.md [[email protected] myProject] # echo "##myProject">>myProject.md [[email protected] myProject] # git add . [[email protected] myProject] # git commit -m"add md file" [[email protected] myProjet] # git remote add origin ssh://[email protected]/~/myProject/.git [[email protected] myProjet] # git remote -v origin ssh : //root @localhost/~ /myProject/ .git (fetch) origin ssh : //root @localhost/~ /myProject/ .git (push) |
Note: git init or git init -- bare. What is the difference between the two?
Added -- bare is called Bare repository.
To put it simply, the significance of the bare repository is to centrally manage the server to manage the submission of multiple developers.
Even if -- bare is not added, the developer can still clone the project, but the following information is prompted when pushing to the repository and fails:
Remote: Error: refusing to update checked out branch: refs/heads/Master
Remote: Error: by default, updating the current branch in a non-bare Repository
Remote: Error: is denied, because it will make the index and work tree inconsistent
Remote: Error: With what you pushed, and will require 'git reset -- hard' to match
Remote: Error: The work tree to head.
Remote: Error:
Remote: Error: You can set 'receive. denycurrentbranch' configuration variable
Remote: Error: 'ignore' or 'warn' in the remote repository to allow pushing
Remote: Error: Its Current branch; however, this is not recommended unless you
Remote: Error: arranged to update its work tree to match what you pushed in some
Remote: Error: Other way.
Remote: Error:
Remote: Error: to squelch this message and still keep the default behaviour, Set
Remote: Error: 'receive. denycurrentbranch' configuration variable to 'refuse '.
If the local push is only performed on the server, there is no problem. That is to say, git init is just for yourself.
The directory after git init contains two things:. Git and the actual working directory, while the bare repository is only. Git.
That is to say, the first step is wrong. For init, it is enough to git init -- bare in the directory, and remote add is not required.
In this way, you can clone and push it.
1234567891011121314151617 |
$ git clone [email protected]:myProject Cloning into ‘myProject‘ ... warning: You appear to have cloned an empty repository. Checking connectivity... done $ cd myProject/ $ touch pushTest.txt $ echo "push test" >pushTest.txt $ git add . warning: LF will be replaced by CRLF in pushTest.txt. The file will have its original line endings in your working directory. $ git commit -m "test file" [master (root-commit) 05f0722] test file warning: LF will be replaced by CRLF in pushTest.txt. The file will have its original line endings in your working directory. 1 file changed, 1 insertion(+) create mode 100644 pushTest.txt $ git push |
The system prompts you to enter the password during clone or push,
Several developers have nothing to do with a user name and password. It doesn't make sense for each user to set their own user name and password several times.
Let developers generate key pair and give the public key to me for management.
You can use the following command to generate (RSA or DSA, or add other parameters as needed ):
After the command is executed, the key is generated under. SSH in the user directory, and The. Pub file is sent to the Administrator.
Assume that the file name obtained by the Administrator is id_rsa.test.pub and is stored in the user directory. perform the following operations to add the permission and confirm:
123 |
[[email protected] ~] # cat id_dsa.test.pub >> ~/.ssh/authorized_keys [[email protected] ~] # cd .ssh/ [[email protected] . ssh ] # cat authorized_keys |
Well, the above is the creation and authentication of the remote database.
Git-create and authenticate remote Libraries