获取 GitHub 存储库的本地副本,跟踪更改并将更新推送回远程。

4

我在GitHub上有一个存储库,我想用从中提取的文件夹中所做的更改来更新它。

对于一个新的Git用户来说,在使用cd目录之后应该执行哪些步骤,不要使用术语或缩写?

包括如何跟踪对任何文件所做的本地更改,然后如何将这些更改和更新发送回远程存储库。

4个回答

9

最简单的流程是这样的:

# clone the repository (from github, for example)
git clone git@github.com:username/reponame.git
cd reponame    

# edit some files

# add them to the index
git add file1.txt
git add file2.gif

# review your changes
git status    

# commit the changes
git commit -m "Decription of my change"

# push them back to the remote repository
git push origin master

这是基本流程,可以帮助您上手。但是,有很多关于学习git基础的资源 资料,我强烈建议您浏览一下。起步并没有看起来那么困难。

我知道当某些看似过于复杂的事情让我烦恼时,我会变得不理性。更改实际上是在存储库中已经存在的文件中进行的。我可以只使用 git add . 然后执行 status/message/push 操作吗? - Elmo

3

我猜你是一个独立工作的人,所以这很简单。

1) 通过SSH使用"git clone"完成。Github网站会提供克隆URL。
2) 只需在本地工作,这就是分布式版本控制系统的用途:-) 然后"git commit"你所开发的内容。
3) 你需要将你的分支"git push"到Github上。其他人就可以获取它了。

这些都是基础知识,当你对这个最简单的工作流程感到自信时,你可以学习很多适合你编码实践的东西,重写你的历史和很多好玩的Git技巧。
并且你将学会如何与其他人合作、合并和变基。


2

首先,你需要进入代码库:

cd My-Repository

您需要将所有想要提交的文件添加到代码库中:

git add my-code

你提交更改:
git commit -m "Commit-Message"

然后,您将更改推送到Github(请确保通过SSH或HTTPS克隆它)。在使用分支时,您必须将“master”替换为正确的分支名称。

git push origin master

2
以下是你需要的简要概述:

以下是您所需内容的简要概述:

  1. Create a local version of the remote repository on my computer:

    git clone <remote-url>
    
  2. Start making and tracking changes to the local copy:

    # Add or modify some files.
    # Then add them to Git's staging area:
    git add <file1> <file2> <etc>
    
    # Commit the changes
    git clone -m "Your commit message"
    
  3. When you're done making changes, push them back to the remote repository.

    git push origin <branch>
    

    When you push to the remote repository, your changes may be rejected because there are new commits on the remote that you need to merge your work with, in which case you can

    git fetch origin
    
    git merge origin/branch
    # Or
    git rebase origin/branch
    

    to synchronize your local work with the new changes, then try pushing again. Avoid rebasing commits that are already shared with other people though, because it will force them to resynchronize their work with the rewritten commits (if your team is comfortable with this, then this is feasible).

你仍应该阅读《Pro Git》书籍

我上面提到的只是一个简短的总结。我甚至没有讲解如何解决合并冲突。

如果你真的想熟练掌握Git,我仍然强烈建议你阅读免费在线的Pro Git书籍,特别是第1-3章和第6-6.5章。甚至有iPad、Kindle和PDF版本可供免费下载。


感谢您的帮助。我认为我需要进入使用Git的过程,并期望自己不会马上开始编码。我需要抽出一些时间来彻底学习Git本身,然后再稍后使用它。每次我开始时,我只想编码,但最终却对Git感到烦恼,转而做其他事情。 - Canadian Coder
@CanadianCoder 考虑到 Git 是围绕代码的所有工作流程的基础,我认为在您真正开始其他任何事情之前,您确实需要具备一定的熟练度。 - user456814

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接