Set the public key, you can upload and download
- adopt
git pull
&&git push
&&git clone
1. Two lines of command
Step 0 preparation
- Create a new GitHub repository (repositories), any repository name
- 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)
- 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 upstream
When uploading for the first time, record the match and push it to the master branch of origin warehouse-u origin master
Only need to write for the first time, later directlygit push
Just 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 push
The 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
- 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 use
https://
Address, every time to enter the password
- 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 pull
First, merge the remote branch to the corresponding local branch - If the remote branch has not been updated, it can be omitted
git pull
-
-u origin master
It means to set up the upstream branch - After that, it can be set directly
git 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 pull
In 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
- How to upload other branches
- Method 1
git push origin x:x
git push
Warehouse name sub branch name (source: local x): Branch Name (target: remote x)
- Method 2
git checkout x
git push -u origin x
git push
Warehouse 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