Linux Git - 将 Github 存储库与本地存储库同步?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13036064/
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-08-06 17:35:23  来源:igfitidea点击:

Git - Syncing a Github repo with a local one?

linuxgitgithub

提问by Keith Gadberry

First off, forgive me if this is a duplicate question. I don't know anything but the basic terminology, and it's difficult to find an answer just using laymen's terms.

首先,如果这是一个重复的问题,请原谅我。除了基本术语我什么都不知道,仅使用外行的术语很难找到答案。

I made a project, and I made a repository on Github. I've been able to work with that and upload stuff to it for some time, on Windows. The Github Windows application is nice, but I wish there was a GUI for the Linux git.

我做了一个项目,我在 Github 上做了一个存储库。一段时间以来,我已经能够在 Windows 上使用它并将内容上传到它。Github Windows 应用程序很好,但我希望 Linux git 有一个 GUI。

I want to be able to download the source for this project, and be able to edit it on my Linux machine, and be able to do git commit -m 'durrhurr'and have it upload it to the master repository.

我希望能够下载该项目的源代码,并能够在我的 Linux 机器上对其进行编辑,并且能够将git commit -m 'durrhurr'其上传到主存储库。

采纳答案by Eric Y

Forgive me if you've already done most of this:

如果您已经完成了大部分工作,请原谅我:

The first step is to set up your ssh keys if you are trying to go through ssh, if you are going through https you can skip this step. Detailed instructions are provided at https://help.github.com/articles/generating-ssh-keys

如果您尝试通过 ssh,则第一步是设置您的 ssh 密钥,如果您正在通过 https,则可以跳过此步骤。https://help.github.com/articles/generating-ssh-keys提供了详细说明

The next step is to make a local clone of the repository. Using the command line it will be git clone <url>The url you should be able to find on your github page.

下一步是制作存储库的本地克隆。使用命令行它将是git clone <url>您应该能够在您的 github 页面上找到的 url。

After that you should be able to commit and push over the command line using git commit -am "commit message"and git push

之后,您应该能够使用git commit -am "commit message"和提交并推送命令行git push

回答by sampson-chen

You can use SmartGitfor a GUI for git on Linux: http://www.syntevo.com/smartgit/index.html

您可以SmartGit在 Linux 上用于 git 的 GUI:http: //www.syntevo.com/smartgit/index.html

But learning git first on the command line is generally a good idea:

但是首先在命令行上学习 git 通常是一个好主意:

Below are some basic examples assuming you are only working from the masterbranch:

以下是一些基本示例,假设您仅在master分支中工作:

Example for starting a local repo based on what you have from github:

根据您从 github 获得的内容启动本地存储库的示例:

git clone https://github.com/sampson-chen/sack.git

To see the status of the repo, do:

要查看 repo 的状态,请执行以下操作:

git status

Example for syncing your local repo to more recent changes on github:

将本地存储库同步到 github 上最近更改的示例:

git pull

Example for adding new or modified files to a "stage" for commit

将新文件或修改文件添加到“阶段”以进行提交的示例

git add /path/file1 /path/file2

Think of the stage as the files that you explicitly tell git to keep track of for revision control. git will see the all the files in the repo (and changes to tracked files), but it will only do work on the files that you add to a stage to be committed.

将阶段视为您明确告诉 git 跟踪修订控制的文件。git 将看到存储库中的所有文件(以及对跟踪文件的更改),但它只会处理您添加到要提交的阶段的文件。

Example for committing the files in your "stage"

提交“阶段”中的文件的示例

git commit

Example for pushing your local repo (whatever you have committed to your local repo) to github

将本地存储库(无论您已提交给本地存储库的内容)推送到 github 的示例

git push

回答by Rag Sagar

  • To start working on the project in linux, clone the repo to linux machine. Add the ssh public key to github. Add your username and email to git-config.
  • For GUI you can use gitg.
  • 要开始在 linux 中处理该项目,请将 repo 克隆到 linux 机器。将 ssh 公钥添加到 github。将您的用户名和电子邮件添加到 git-config。
  • 对于 GUI,您可以使用 gitg。

PS : Get used to git cli, It is worth to spend time on it.

PS:习惯git cli,值得花时间。

回答by AlexP

What you need to do is clone your git repository. From terminal cdto the directory you want the project in and do

您需要做的是克隆您的 git 存储库。从终端cd到您希望项目所在的目录并执行

git clone https://github.com/[username]/[repository].git

git clone https://github.com/[username]/[repository].git

Remember notto use sudoas you will mess up the remote permissions.

记住不要使用,sudo因为你会搞乱远程权限。

You then need to commit any changes locally, i.e your git commit -mand then you can do.

然后您需要在本地提交任何更改,即您的git commit -m然后您就可以做到。

git push

git push

This will update the remoterepository.

这将更新远程存储库。

Lastly if you need to update your localproject cdto the required directory and then:

最后,如果您需要将本地项目更新cd到所需目录,然后:

git pull

git pull