简体   繁体   English

Git-将Github仓库与本地仓库同步吗?

[英]Git - Syncing a Github repo with a local one?

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. 我做了一个项目,并在Github上做了一个存储库。 I've been able to work with that and upload stuff to it for some time, on Windows. 在Windows上,我已经能够使用它并将内容上传到其中一段时间​​了。 The Github Windows application is nice, but I wish there was a GUI for the Linux git. 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'并将其上传到主存储库。

You can use SmartGit for 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 master branch: 以下是一些基本示例,假设您仅在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: 要查看回购的状态,请执行以下操作:

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跟踪修订控制的文件。 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将看到存储库中的所有文件(以及对跟踪文件的更改),但是它将仅对添加到要提交的阶段的文件起作用。

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

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. 第一步是如果您尝试通过ssh,则设置ssh密钥;如果您通过https,则可以跳过此步骤。 Detailed instructions are provided at https://help.github.com/articles/generating-ssh-keys 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提交并推送命令行

What you need to do is clone your git repository. 您需要做的是克隆git存储库。 From terminal cd to the directory you want the project in and do 从终端cd到您要在其中执行项目的目录

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

Remember not to use sudo as you will mess up the remote permissions. 切记不要使用sudo因为这样会弄乱远程权限。

You then need to commit any changes locally, ie your git commit -m and then you can do. 然后,您需要在本地提交所有更改,即git commit -m ,然后就可以进行。

git push

This will update the remote repository. 这将更新远程存储库。

Lastly if you need to update your local project cd to the required directory and then: 最后,如果您需要将本地项目cd更新到所需目录,然后:

git pull

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

PS : Get used to git cli, It is worth to spend time on it. PS:习惯git cli,值得花时间在上面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM