利用git上传项目到github

首先需要有一个github账号,然后电脑中安装了git。

首先是配置ssh公钥到github上。先进入.ssh目录,利用ssh-Keygen指令生成公钥

xxp@ubuntu:~/.ssh$ ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/home/xxp/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/xxp/.ssh/id_rsa.
Your public key has been saved in /home/xxp/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:i0SSEkPDIMFW7L7/0RavL1Kb6ijAXDdw8fR4FwC9ANQ xxp@ubuntu
The key's randomart image is:
+---[RSA 2048]----+
|==B..++oo...     |
|.o.* ooEo.  .    |
|. o = .o.o..     |
|   + =  ...      |
|o o . o S.       |
| + . . ..oo      |
|  . . ..ooo.     |
|   o  ..o+.      |
|    ooo+o.o.     |
+----[SHA256]-----+
xxp@ubuntu:~/.ssh$ 

xxp@ubuntu:~/.ssh$ ls
id_rsa  id_rsa.pub

生成之后会有两个指令,一个是私钥一个为公钥。将公钥配置到github账号才能将项目从本地推送到github。

选择github账号-->settings-->SSH and GPG keys-->New SSH key,然后将id_rsa.pub里面的内容填入即可。

配置完就可以通过git clone下载github上面的项目源码。通过git remote配置源及git push指令推送项目到github。

# 配置完之后就可以clone项目了

xxp@ubuntu:~$ cd git_learning/
xxp@ubuntu:~/git_learning$ git clone [email protected]:1621521894/Ui_Test.git
正克隆到 'Ui_Test'...
The authenticity of host 'github.com (52.74.223.119)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': yes
Warning: Permanently added 'github.com,52.74.223.119' (RSA) to the list of known hosts.
remote: Counting objects: 127, done.
remote: Compressing objects: 100% (81/81), done.
remote: Total 127 (delta 38), reused 124 (delta 37), pack-reused 0
接收对象中: 100% (127/127), 398.03 KiB | 98.00 KiB/s, 完成.
处理 delta 中: 100% (38/38), 完成.
检查连接... 完成。

# 配置源
xxp@ubuntu:~/git_learning/Ui_Test$ git remote 
origin
xxp@ubuntu:~/git_learning/Ui_Test$ git remote -v
origin	[email protected]:1621521894/Ui_Test.git (fetch)
origin	[email protected]:1621521894/Ui_Test.git (push)
# 添加源
xxp@ubuntu:~/git_learning/Ui_Test$ git remote add 
origin	[email protected]:1621521894/Ui_Test.git

# 设置用户信息
xxp@ubuntu:~/git_learning/Ui_Test$ git config --global user.email "[email protected]"
xxp@ubuntu:~/git_learning/Ui_Test$ git config --global user.name "pyxxp"
xxp@ubuntu:~/git_learning/Ui_Test$ ls
adb_command  APK续航测试用例报告.xlsx  auto_fill.py  data  README.md  ut
xxp@ubuntu:~/git_learning/Ui_Test$ vim README.md 
xxp@ubuntu:~/git_learning/Ui_Test$ git commit -am "一个修改测试"
[master 8d2ff32] 一个修改测试
 1 file changed, 1 insertion(+), 1 deletion(-)
xxp@ubuntu:~/git_learning/Ui_Test$ git push origin master:master
对象计数中: 3, 完成.
压缩对象中: 100% (3/3), 完成.
写入对象中: 100% (3/3), 363 bytes | 0 bytes/s, 完成.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To [email protected]:1621521894/Ui_Test.git
   e76dbf6..8d2ff32  master -> master

# 拉取远程并更新
git fetch

git origin/master

# 在本地新建项目推送不到远程是因为远程仓库也有README文件。可以拉取远程并跟新之后再推送

猜你喜欢

转载自blog.csdn.net/weixin_40327641/article/details/80462202