我们经常发布文档更新,此页面的翻译可能仍在进行中。有关最新信息,请访问英文文档。如果此页面上的翻译有问题,请告诉我们

Syncing your branch

As commits are pushed to your project on GitHub, you can keep your local copy of the project in sync by pulling from the remote repository.

本文内容

About branch synchronization

You can sync your local branch with the remote repository by pulling any commits that have been added to the branch on GitHub since the last time you synced. If you make commits from another device or if multiple people contribute to a project, you will need to sync your local branch to keep the branch updated.

When you pull to your local branch, you only update your local copy of the repository. To update your branch on GitHub, you must push your changes. For more information, see "Pushing changes to GitHub."

To add changes from one branch to another branch, you can merge the branches. To apply changes to your branch from another branch in the same repository, you can merge the other branch into your branch on GitHub Desktop. To request that changes from your branch are merged into another branch, in the same repository or in another repository in the network, you can create a pull request on GitHub Desktop. For more information, see "Merging another branch into your project branch" and "About pull requests."

Some workflows require or benefit from rebasing instead of merging. By rebasing you can reorder, edit, or squash commits together. For more information, see "About Git rebase" and "Rebasing your project branch onto another branch."

Pulling to your local branch from the remote

  1. In GitHub Desktop, use the Current Branch drop-down, and select the local branch you want to update.
  2. To check for commits on the remote branch, click Fetch origin
    The Fetch origin button
  3. To pull any commits from the remote branch, click Pull origin or Pull origin with rebase.
    The Pull origin button
  4. 使用文本编辑器、命令行或其他工具(根据您的偏好)解决任何合并冲突。

Merging another branch into your project branch

  1. 在应用程序的顶部,单击 Current Branch(当前分支)

    当前分支下拉菜单

  2. 单击 Choose a branch to merge into BRANCH(选择要合并到分支的分支选项)

    在分支菜单中选择分支选项

  3. 单击要合并到当前分支的分支,然后单击 Merge BRANCH into BRANCH(将分支合并到分支)

    Note: If there are merge conflicts, GitHub Desktop will warn you above the Merge BRANCH into BRANCH button. You will not be able to merge the branches until you have resolved all conflicts.

    The Merge button

  4. 单击 Push origin(推送源)Force push origin(强制推送源) 将您的更改推送到远程。

    推送按钮

Rebasing your project branch onto another branch

  1. In the menu bar, use the Branch drop-down and click Rebase Current Branch.
    Rebase Current Branch in branch dropdown
  2. Click the branch you want to rebase into the current branch, then click Start rebase.
    Start rebase button
  3. If you're sure you want to rebase, click Begin rebase.
    Begin rebase button
  4. 使用文本编辑器、命令行或其他工具(根据您的偏好)解决任何合并冲突。
  5. To push your local changes, click Force push origin.
    Force push origin
  1. Use the Branch drop-down and click Rebase Current Branch.
    Rebase Current Branch in branch dropdown
  2. Click the branch you want to rebase into the current branch, then click Start rebase.
    Start rebase button
  3. If you're sure you want to rebase, click Begin rebase.
    Begin rebase button
  4. 使用文本编辑器、命令行或其他工具(根据您的偏好)解决任何合并冲突。
  5. To push up your local changes, click Force push origin.
    Force push origin

Further Reading

  • "Pull" in the GitHub glossary
  • "Merge" in the GitHub glossary
  • "Rebase" in the GitHub glossary

问问别人

找不到要找的内容?

联系我们