知乎专栏 |
查看远程仓库
git remote show originneo@MacBook-Pro-Neo ~> git remote -v origin git@192.168.30.5:netkiller.cn/www.netkiller.cn.git (fetch) origin git@192.168.30.5:netkiller.cn/www.netkiller.cn.git (push)neo@MacBook-Pro-M2 ~/netkiller (dev)> git remote get-url origin ssh://git@gitlab.netkiller.cn/galaxy/ensd-fscs.git
添加远程仓库
git remote add origin git@localhost:example.git
添加多个远程仓库
git remote add origin git@localhost:example.git git remote add another https://gitcafe.com/netkiller/netkiller.gitcafe.com.git git push origin master git push another master
git remote rename origin old-origin
修改远程仓库
git remote set-url origin git@gitlab.netkiller.cn:netkiller.cn/www.netkiller.cn.git git remote set-url origin https://gitlab.netkiller.cn/netkiller.cn/www.netkiller.cn.git
First we need to setup a user with a home folder. We will store all the repositories in this users home folder.
sudo adduser git
Rather than giving out the password to the git user account use ssh keys to login so that you can have multiple developers connect securely and easily.
Next we will make a repository. For this example we will work with a repository called example. Login as the user git and add the repository.
login to remote server
ssh git@REMOTE_SERVER
once logged in
sudo mkdir example.git cd example.git sudo git --bare init Initialized empty Git repository in /home/git/example.git/
That’s all there is to creating a repository. Notice we named our folder with a .git extension.
Also notice the ‘bare’ option. By default the git repository assumes that you’ll be using it as your working directory, so git stores the actual bare repository files in a .git directory alongside all the project files. Since we are setting up a remote server we don’t need copies of the files on the filesystem. Instead, all we need are the deltas and binary objects of the repository. By setting ‘bare’ we tell git not to store the current files of the repository only the diffs. This is optional as you may have need to be able to browse the files on your remote server.
Finally all you need to do is add your files to the remote repository. We will assume you don’t have any files yet.
mkdir example cd example git init touch README git add README git commit -m 'first commit' git remote add origin git@REMOTE_SERVER:example.git git push origin master
replace REMOTE_SERVER with your server name or IP