建立实验室来试验 GIT

发布于 2024-09-30 08:19:19 字数 373 浏览 3 评论 0原文

我是一名 Linux 新手(大约 6 个月)。

我使用 Git 已经有一段时间了,现在我想开始学习更高级的东西。我想学习的是处理/管理遥控器的各种方法。

所以我的问题是——如何在本地设置“远程”?是否可以创建两个文件夹,例如:

/home/my_user/git_experiment/remote_branch
/home/my_user/git_experiment/local_branch 

并将 local_branch 文件夹设置为跟踪 remote_branch 文件夹,就像 remote_branch 是 GitHub 上的存储库一样?

I'm a newbie (like 6 months) Linux user.

I'm using Git for quite a while, and now I'd like to start learning more advanced stuff. What I'd like to learn is a variety of ways to handle/manage remotes.

So my question is — how can I setup a "remote" locally? Is it possible to create two folders, for example:

/home/my_user/git_experiment/remote_branch
/home/my_user/git_experiment/local_branch 

and set local_branch folder to track remote_branch folder just like if remote_branch would be a repo on GitHub?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

杯别 2024-10-07 08:19:19

遥控器只是一个克隆,您可以通过某种方式访问​​它。通常它是通过 git 协议或 http(用于读取)和 ssh 或 https(用于写入)进行访问,但文件系统访问也同样有效。您需要做的就是克隆您的存储库:

# clone project into project2
git clone project project2

原始远程将自动在project2中设置,指向项目,就像您习惯的那样。您可以在项目中添加相应的远程,指向项目2,然后尝试执行您想要执行的任何获取和拉取操作。

如果您想尝试推送,请确保创建一个裸克隆来推送:

# the .git suffix is traditional for bare repos, since they're
# basically the .git directory of a normal repo
git clone --bare project project.git
cd project
git remote add bare-remote ../project.git
# now you've got a remote to push to

我不确定为什么将它们命名为“local_brach”和“remote_brach”(这是否意味着“分支”?)。这些不是分支机构。他们是克隆人;他们可以有自己的全套分支,可能还有一些相应的分支。

A remote is just a clone which you have some way to access. Commonly it's accessed via the git protocol or http (for reading) and ssh or https (for writing), but filesystem access works just as well. All you need to do is clone your repo:

# clone project into project2
git clone project project2

The origin remote will automatically be set up in project2, pointing to project, just like you're used to. You could add a corresponding remote in project, pointing to project2, and try out whatever fetching and pulling you want to do.

If you want to try out pushing, make sure you make a bare clone to push into:

# the .git suffix is traditional for bare repos, since they're
# basically the .git directory of a normal repo
git clone --bare project project.git
cd project
git remote add bare-remote ../project.git
# now you've got a remote to push to

I'm not sure why you're naming them "local_brach" and "remote_brach" (is that meant to say "branch"?). These aren't branches. They're clones; they can have their own full sets of branches, probably with some corresponding.

长不大的小祸害 2024-10-07 08:19:19

有可能,git remote 参数可以只是一个路径:

$ git remote add my-remote /home/my_user/git_experiment/remote_brach

It is possible, the <url> parameter to git remote can just be a path:

$ git remote add my-remote /home/my_user/git_experiment/remote_brach
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文