[getting started with git 6] GitHub common operation process of GIT remote warehouse 2_ upload

Time:2021-3-2

Set the public key, you can upload and download

  • adoptgit pull&&git push&&git clone

1. Two lines of command

Step 0 preparation

  1. Create a new GitHub repository (repositories), any repository name
  2. In the quick settings, SSH is the default (do not choose HTTPS, pit, each time you need to enter a password, inconvenient, scold you to death)
  3. Copy the code in the page (turn off translation), “copy the SSH address (note that it starts with git instead of the HTTPS address)”

Existing local warehouse

git remote add origin [email protected]:yourName/yourRepoName.git
  • Tell the local warehouse the address corresponding to the remote warehouse, and the warehouse name is origin

Step 1 upload for the first time:

git push -u origin master
  • -u upstreamWhen uploading for the first time, record the match and push it to the master branch of origin warehouse
  • -u origin masterOnly need to write for the first time, later directlygit pushJust fine
  • Master (local) – > Master (GitHub)
  • Refresh the remote warehouse page to see the uploaded content

There is no local warehouse, when it is completely new

echo "# RepoName" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin [email protected]:yourName/yourRepo Name.git
git push -u origin master
  • git pushThe upload is a branch submitted by the local warehouse, not the current code
  • You can submit multiple branches:
git branch x
git checkout x
## ... change sth ...
git add .
git commit -am "log"
git push -u origin x

Note to add – u, because this is the first time to upload this branch * [new branch]

  • X (local) – > x (GitHub)
  • Like I want to see the branches:git branch, I want to view the remote warehouse:git remote

Summary

  1. Associate your new remote warehouse
git remote add origin [email protected]
  • Add the address of the remote warehouse locally
  • Origin is the default name of the remote warehouse. It can be changed, but not recommended
  • Do not usehttps://Address, every time to enter the password
  1. Initial commit to remote warehouse
git push -u origin master
  • Push the local master branch to the master branch of the remote origin
  • If the remote warehouse is created by adding README.md And other reasons, resulting in the remote warehouse and your local warehouse file is inconsistent, prompt you should git pull… Just git pull
  • git pullFirst, merge the remote branch to the corresponding local branch
  • If the remote branch has not been updated, it can be omittedgit pull
  • -u origin masterIt means to set up the upstream branch
  • After that, it can be set directlygit pull;git push

eg.For example, there is a repo2 warehouse

git remote add repo2 [email protected]:yourName/git-demo-02.git
git push -u repo2 master

Not directlygit pullIn this case, you need to copy the master branch of repo2 warehouse to the current master branch:

git checkout master
git pull repo2 master:master

master -> repo2/master

git push -u repo2 master

The merge is rejected because there is no association. You can use forced merge cautiously:

git push -u repo2 master -f

Be careful of your colleagues

  1. How to upload other branches
  • Method 1
git push origin x:x

git pushWarehouse name sub branch name (source: local x): Branch Name (target: remote x)

  • Method 2
git checkout x
git push -u origin x
  • git pushWarehouse name sub branch name
  • GitHub remote warehouse is a copy of local warehouse (Branch) (backup. Git /)
  • The location of the local warehouse in the hard disk (relative path) does not affect the remote warehouse
  • A remote repository is equivalent to a folder on GitHub. The folder name in Git clone is the name of the repository
  • Like I want to see the branches:git branch, I want to view the remote warehouse:git remote
  • Name to distinguish origin from remote warehouse:
  • What does the origin in GitHub mean

·To be continued·


Reference article

  • What’s the difference between ‘origin’ and ‘remote’ in Git command?
  • Meaning of origin of GIT
  • Git remote warehouse.pdf

Related articles

  • nothing

  • By Joel
  • Article link:
  • Copyright notice
  • Non free reprint – non commercial – non derivative – keep signature
  • A brief introduction to river digging

Recommended Today

Rust and python: why rust can replace Python

In this guide, we compare the rust and python programming languages. We will discuss the applicable use cases in each case, review the advantages and disadvantages of using rust and python, and explain why rust might replace python. I will introduce the following: What is rust? What is Python? When to use rust When to […]