惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
Hugging Face - Blog
Hugging Face - Blog
博客园 - 聂微东
量子位
S
SegmentFault 最新的问题
V
Visual Studio Blog
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
小众软件
小众软件
Stack Overflow Blog
Stack Overflow Blog
Vercel News
Vercel News
D
Docker
J
Java Code Geeks
博客园 - 三生石上(FineUI控件)
博客园 - Franky
Recent Announcements
Recent Announcements
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
MongoDB | Blog
MongoDB | Blog
D
DataBreaches.Net
Y
Y Combinator Blog
云风的 BLOG
云风的 BLOG
V
V2EX

jdhao's digital space

Conversion between base64 and OpenCV or PIL Image 腾讯云对象存储博客图床开启 CDN 加速(不需要购买额外域名) Search and Replace in Multiple Files in Vim/Neovim Change Table Column Width in LaTeX Image or Table Side by Side in LaTeX LaTeX 并排显示图像或表格 Firenvim: Neovim inside Your Browser Content inside HTML tags missing in Latest Hugo? Creating Markdown Front Matter with Ultisnips Labelme JSON 标注格式转 voc XML 格式 Nifty Nvim Techniques That Make My Life Easier -- Series 6 macOS 下如何为视频制作字幕 Running Command Asynchronously inside Neovim Resolving Merge Conflict after Git Stash Pop Pylint: command not found? A Hands-on Experience with Neovim's Built-in LSP Support How to Convert PDF to Images with Imagemagick 互联网上常用缩略语集锦 File Backup in Neovim Converting PDF Pages to Images with Poppler Nifty Nvim Techniques That Make My Life Easier -- Series 5 Neovim Configuration for System-wide Use How to sort a list of tuple or list in Python -- lambda or itemgetter? Building A Vim Statusline from Scratch 人类第一颗原子弹爆炸始末 Distributed Training in PyTorch with Horovod Learning Expect Programming Essential Knowledge about SSH Nifty LaTeX Techniques -- Series 1 更改 Adsense 邮寄地址,重新寄送 PIN
How to Push Local Git Repo to Remote Repo in GitHub
2018-05-16 · via jdhao's digital space

There are two basic cases when we push our local repo to remote repo. These two cases differ in their settings. But sometimes, we are easily confused.

First scenario#

The first case is that you have created a local repo and want to store it on GitHub later. In this case, your usual work flow for local repo is:

  1. Initialize the local repo (git init)
  2. Write you code and document, etc.
  3. Add changes to index (e.g., git add . )
  4. Commit the changes (git commit -m "some message")
  5. Repeat step 2 – 4

Then, at some point, you want to push this local repo to GitHub. First, you need to create a new repo in GitHub. But be careful that you should not create a README file in this repo.

If you do create a README file, you will encounter errors when you try to push to this remote repo:

hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

If you try to pull from the remote repo to fix the above error, you will then see error message such as:

fatal: refusing to merge unrelated histories

In order to spare yourself from these troubles, just do not create a README file! Just create an empty repo.

After you have created an empty remote repo, you should add it as one of your remote. You can then push to it smoothly.

git remote add upstream <your_repo_url>
git push upstream master

If you accidentally created it README file, you can also force to push to this remote repo:

git push -f upstream master

The above option -f will erase the commit on the remote repo. You can then force push to the remote repo.

Second scenario#

The other case is that you already have a remote repo1 and you want to continue to develop it locally. In this case, you should first clone this remote repo and then develop it locally.

git clone <your_remote_repo>

After cloning this remote repo, you can develop it locally. In this case, you do not have to manually add this repo as your remote. It will be added as your remote by default with the name origin.

In order to push to this repo, we use the following command:

References#