推送到远程

Git 中级

George Boorman

Curriculum Manager, DataCamp

从远程拉取

从远程仓库拉取

Git 中级

推送到远程

推送到远程

Git 中级

git push

  • 先在本地保存更改!
git push remote local_branch
  • 将更改从 local_branch 推送到 remote

  • 将本地仓库 main 分支的更改推送到 origin

git push origin main
Git 中级

推送/拉取流程

从远程拉取到本地仓库

Git 中级

推送/拉取流程

本地进行项目开发

Git 中级

推送/拉取流程

将更新后的本地仓库推送到远程

Git 中级

先推送

  • 在拉取前先将 main 推送到远程
git push origin main
Git 中级

远程/本地冲突

git push origin main 被拒绝的输出

Git 中级

远程/本地冲突

git push origin main 被拒绝的输出,标注远程 URL

Git 中级

远程/本地冲突

git push origin main 被拒绝的输出,标注结果

Git 中级

远程/本地冲突

git push origin main 被拒绝的输出,标注原因和建议

Git 中级

避免冲突

  • 先从远程拉取
git pull origin main

git_pull_nano_editor.gif

Git 中级

无编辑拉取

git pull --no-edit origin main
  • 不推荐,除非对项目历史非常有把握!
Git 中级

推送新的本地分支

  • 本地在 hotfix 分支上工作

  • 远程不存在 hotfix

Git 中级

创建新的远程分支

  • hotfix 仅存在于本地
git push origin hotfix
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 349 bytes | 349.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
remote: 
remote: Create a pull request for 'hotfix' on GitHub by visiting:
remote:      https://github.com/datacamp/project/pull/new/hotfix
remote: 
To https://github.com/datacamp/project
 * [new branch]      hotfix -> hotfix
branch 'hotfix' set up to track 'origin/hotfix'.
Git 中级

Vamos praticar!

Git 中级

Preparing Video For Download...