问题
I'm trying GIT and i ran into an issue.
I have my local machine (let's call it MAC) and a server (let's call it SERVER). It's a local server, I access it through an alias in my desktop.
I want to create a GIT repository in this SERVER, in which I'll keep my files and pull these files into my MAC. Then, after editing, I want to commit these changes to SERVER.
SERVER MAC SERVER
source -->> copy -->> commit
It sounds very GIT-like, but I can only find these tutorials for remote servers, with logins and passwords and such. How to do that with a local server?
Other people use this local server and it would be nice if they could pull and commit this same SERVER repository.
Thanks a lot.
ps: I'm using SourceTree GUI but I'm no stranger to terminal.
回答1:
There is no difference in accessing a central Git repository on local and remote servers. All tutorials are valid in either case. For the basic access you simply need:
- Create a normal user account on the server (e.g. git or george).
- Set up a SSH key access to that account. There are many tutorials online, just pick one. For example Github tutorial. The objective is that when you are on your Mac you can SSH to the user account on the server without a username/password, just with the key.
- Login to the user account on the server create a bare Git repository.
That's it, then you can access that repository from your Mac.
For example, assume that the server name is myserver.com
and it's IP is 192.168.1.50
. You login to that server over SSH:
ssh george@192.168.1.50
If the key is set up correctly, you are now logged in (without providing username/password). Now create the bare repository:
mkdir mygit
cd mygit
mkdir myrepository.git
cd myrepository.git/
git --bare init
Then on the Mac create a new repository:
mkdir mylocalrepo
cd mylocalrepo
git init
echo "sometext" > firstfile.txt
git add firstfile.txt
git commit -m "First commit"
Now you can specify the repository created on the server as the remote repository for your local repository. On your Mac (or any other machine on which you want to access that repository):
git remote add origin george@192.168.1.50:mygit/myrepository.git
git push origin master
Alternatively, use the server name rather than IP, and a different remote name:
git remote add origin2 george@myserver.com:mygit/myrepository.git
git push origin2 master
Once you have those basics working you can then start thinking about adding a WWW interface.
来源:https://stackoverflow.com/questions/36896958/using-git-on-local-server-and-local-pc