git 使用 Github 和多台计算机的最佳方式是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/305805/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 16:06:18  来源:igfitidea点击:

Whats the best way to work with Github and multiple computers?

ruby-on-railsgitgithub

提问by Richard Hurt

I am developing some school grading software and decided to use Github to host the project. After building some code on my Ubuntu box I pushed it to Github and then cloned it down to my MacBook Pro. After editing the code on the MBP I pushed it back to Github. The next morning I tried to update my repo on the Ubuntu box with a git pulland it gave me all kinds of trouble.

我正在开发一些学校评分软件并决定使用 Github 来托管该项目。在我的 Ubuntu 机器上构建了一些代码后,我将它推送到 Github,然后将其克隆到我的 MacBook Pro。在 MBP 上编辑代码后,我将其推回 Github。第二天早上,我尝试用 a 更新我在 Ubuntu 机器上的 repo git pull,但它给我带来了各种各样的麻烦。

Whats the best way to work in this situation? I don't want to fork my own repo and I don't really want to send myself emails or pull requests. Why can't I just treat Github like a master and push/pull from it onto all of my personal repos on different computers?

在这种情况下最好的工作方式是什么?我不想 fork 自己的 repo,也不想给自己发送电子邮件或请求请求。为什么我不能像大师一样对待 Github,然后从它推/拉到我在不同计算机上的所有个人存储库?

采纳答案by webmat

I'll assume your problem was that the machine on which you first created the repo crapped out when you tried to issue the git pullcommand.

我假设您的问题是当您尝试发出git pull命令时,您第一次创建 repo 的机器出问题了。

When you clone an existing git repository (like you did on your 2nd machine, the MacBook Pro), you're automatically set up to so your git pullcommands will automatically merge the remote with your local changes.

当您克隆现有的 git 存储库时(就像您在第二台机器 MacBook Pro 上所做的那样),您会自动设置为,因此您的git pull命令将自动将远程更改与您的本地更改合并。

However, when you initially create a repo and then share it on a remote repository, you have to issue a few commands to make things as automated as a on cloned repo.

但是,当您最初创建一个 repo 然后在远程存储库上共享它时,您必须发出一些命令来使事情像克隆的 repo 一样自动化。

# GitHub gives you that instruction, you've already done that
# git remote add origin [email protected]:user_name/repo_name.git

# GitHub doesn't specify the following instructions
git config branch.master.remote origin
git config branch.master.merge refs/heads/master

These last few instructions configure git so future git pull's from this repo will merge all remote changes automatically.

最后几条指令配置了 git,因此git pull这个 repo 中的future将自动合并所有远程更改。

The following is a bit of shameless self-promotion. If you use Ruby, I have created a Ruby-based tool that lets you deal with all these kinds of things with git remote branches. The tool is called, unsurprisingly, git_remote_branch:-)

下面是一点不要脸的自我宣传。如果您使用 Ruby,我已经创建了一个基于 Ruby 的工具,让您可以使用 git 远程分支处理所有这些类型的事情。不出所料,该工具被称为git_remote_branch:-)

If you don't use Ruby, my tool is probably gonna be too much of a hassle to install. What you can do is look at an old post on my blog, where most of the stuff grb can do for you was explicitly shown. Whip out your git notes file :-)

如果你不使用 Ruby,我的工具安装起来可能会很麻烦。您可以做的是查看我博客上的一篇旧帖子,其中明确显示了 grb 可以为您做的大部分事情。拿出你的 git notes 文件 :-)

回答by dylanfm