Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏

125.5. 远程仓库

125.5.1. 查看远程地址

			

查看远程仓库

		
git remote show
origin
		
			

			
neo@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

125.5.1.1. 显示远程地址

	
neo@MacBook-Pro-M2 ~/w/test (master)> git ls-remote --get-url origin
ssh://git@gitlab.netkiller.cn:/chenjingfeng/test.git	
	
			

125.5.2. 添加远程仓库

添加远程仓库

		
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
		

125.5.3. 修改 origin

		
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
			
		

125.5.4. 删除 origin

		
git remote remove origin		
		
		

删除远程仓库

		
git remote rm origin
		
		

125.5.5. 仓库共享

125.5.5.1. Setting up a git server

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