Git --远程仓库操作-推送/拉取/克隆

git remote -v 查看当前所有远程地址别名

git remote add 别名 远程地址

192:git_demo futantan$ git remote add git_demo https://github.com/Clairedandan/git_demo.git
192:git_demo futantan$ git remote -v 
git_demo    https://github.com/Clairedandan/git_demo.git (fetch)
git_demo    https://github.com/Clairedandan/git_demo.git (push)
192:git_demo futantan$

//github.com/Clairedandan/git_demo.git 来源如上图
git push 别名 分支(一定要指定分支)
但是此时我报了一个error :

192:git_demo futantan$ git push git_demo master 

Username for 'https://github.com': Clairedandan

Password for 'https://Clairedandan@github.com': 

remote: Support for password authentication was removed on August 13, 2021.

remote: Please see https://docs.github.com/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.

fatal: Authentication failed for 'https://github.com/Clairedandan/git_demo.git/'

解决方案如下:https://www.cnblogs.com/clairedandan/p/18049898  

192:git_demo futantan$ git remote add git_demo1 https://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@github.com/Clairedandan/git_demo.git/
192:git_demo futantan$ git remote -v 
git_demo    https://github.com/Clairedandan/git_demo.git (fetch)
git_demo    https://github.com/Clairedandan/git_demo.git (push)
git_demo1    https://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@github.com/Clairedandan/git_demo.git/ (fetch)
git_demo1    https://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@github.com/Clairedandan/git_demo.git/ (push)
192:git_demo futantan$ git push --set-upstream git_demo1 master
fatal: unable to access 'https://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@github.com/Clairedandan/git_demo.git/': LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443 
192:git_demo futantan$ git push --set-upstream git_demo1 master
fatal: unable to access 'https://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@github.com/Clairedandan/git_demo.git/': Failed to connect to github.com port 443: Operation timed out
192:git_demo futantan$ git push --set-upstream git_demo1 master
Branch 'master' set up to track remote branch 'master' from 'git_demo1'.
Everything up-to-date
192:git_demo futantan$ 

也可以推送到别的分支上

192:git_demo futantan$ git checkout new_branch1
Switched to branch 'new_branch1'
192:git_demo futantan$ git push --set-upstream git_demo1 new_branch1
Total 0 (delta 0), reused 0 (delta 0)
remote: 
remote: Create a pull request for 'new_branch1' on GitHub by visiting:
remote:      https://github.com/Clairedandan/git_demo/pull/new/new_branch1
remote: 
To https://github.com/Clairedandan/git_demo.git/
 * [new branch]      new_branch1 -> new_branch1
Branch 'new_branch1' set up to track remote branch 'new_branch1' from 'git_demo1'.
192:git_demo futan

此时都成功push 成功,对应的文件也都能找到

 拉取code 

git pull 别名 分支

git pull git-demo master 

首先在github 中修改master 中的一个文件,然后可以在本地pull 到刚刚改的东西:

192:git_demo futantan$ git pull git_demo1 master
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/Clairedandan/git_demo
 * branch            master     -> FETCH_HEAD
   eaf912c..92ed3e7  master     -> git_demo1/master
Updating eaf912c..92ed3e7
Fast-forward
 hello.txt | 1 +
 1 file changed, 1 insertion(+)
192:git_demo futantan$ 
此时就可以查到本地库是干净的,并且是最新的状态

git clone 库的code 地址
clone 会做如下操作:
1、拉取代码
2、初始化本地仓库
3、创建别名
192:clone futantan$ git clone https://github.com/Clairedandan/git_demo.git
Cloning into 'git_demo'...
remote: Enumerating objects: 22, done.
remote: Counting objects: 100% (22/22), done.
remote: Compressing objects: 100% (17/17), done.
remote: Total 22 (delta 3), reused 15 (delta 2), pack-reused 0
Unpacking objects: 100% (22/22), done.
192:clone futantan$ git branch
192:clone futantan$ ls
git_demo
192:clone futantan$ cd git_demo/
192:git_demo futantan$ git branch 
* main
192:git_demo futantan$ git checkout master
Branch 'master' set up to track remote branch 'master' from 'origin'.
Switched to a new branch 'master'
192:git_demo futantan$ ls
hello.txt        new_branch_test1.txt
192:git_demo futantan$ git remote -v 
origin    https://github.com/Clairedandan/git_demo.git (fetch)
origin    https://github.com/Clairedandan/git_demo.git (push)
192:git_demo futantan$ 

 

 


posted @ 2024-03-03 14:02  正霜霜儿  阅读(10)  评论(0编辑  收藏  举报