git:使用(本地)远程存储库

Posted it_xiangqiang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了git:使用(本地)远程存储库相关的知识,希望对你有一定的参考价值。


使用(本地)远程存储库


现在,您可以基于现有的 Git 存储库创建一个本地裸存储库。为了简化示例,Git 存储库托管在文件系统的本地,而不是 Internet 中的服务器上。

之后,您从裸存储库中提取并推送到裸存储库,以同步存储库之间的更改。

通过克隆操作创建一个裸 Git 仓库

执行以下命令,基于现有 Git 存储库创建裸存储库。

# switch to the first repository
cd ~/repo01

# create a new
git clone --bare . ../remote-repository.git

# check the content of the git repo,
# to the .git directory in repo01
# files might be packed in the bare repository

ls ~/remote-repository.git

练习:克隆裸仓库

克隆裸存储库,并通过以下命令签出新目录中的工作树。

# switch to home
cd ~
# make new
mkdir repo02

# switch to new
cd ~/repo02
# clone
git clone ../remote-repository.git .

练习:使用 push 命令

在其中一个非裸本地存储库中进行一些更改,并通过以下命令将它们推送到裸存储库。

# make some changes in the first repository
cd ~/repo01

# make some changes in the file
echo "Hello, hello. Turn your radio on" > test01
echo "Bye, bye. Turn your radio off" > test02

# commit the changes, -a will commit changes for
# but will not add automatically new
git commit -a -m "Some changes"

# push the changes
git push ../remote-repository.git

练习:使用 pull 命令

要测试示例 Git 存储库中的 ,请切换到其他非裸本地存储库。从远程存储库中拉入最近的更改。然后进行一些更改,并再次将其推送到远程存储库。git pull

# switch to second directory
cd ~/repo02

# pull in the latest changes of your remote repository
git pull

# make changes
echo "A change" > test01

# commit the changes
git commit -a -m "A change"

# push changes to remote repository
# origin is automatically created as we cloned original from this

您可以使用以下命令在第一个示例存储库中拉入更改。

# switch to the first repository and
cd ~/repo01

git pull ../remote-repository.git/

# check the changes


以上是关于git:使用(本地)远程存储库的主要内容,如果未能解决你的问题,请参考以下文章

Git本地存储库提交导出

将本地现有目录连接到现有 Git 远程存储库

是否可以使用Git扩展或Git GUI来管理远程linux ftp服务器上的文件,如本地存储库

如何从本地 Windows 存储库推送到 Windows git 远程服务器

如何将本地更改推送到 Bitbucket 上的远程 Git 存储库

git远程存储库包含未合并到本地分支的提交