1.在github上创建一个新的文件夹
2.打开终端,cd到你存储代码的本地文件夹,在本地文件夹中初始化一个新的git文件夹
(base) pcia1@pcia1-P330:~/demo01_ws$ git init
3.将本地存储库链接到 GitHub:
在 GitHub 存储库页面上,复制为存储库提供的 URL, 如下图所示
在终端里面输入下面的语句, <repository-url>是你刚才在github上面复制的url
git remote add origin <repository-url>
4.将文件添加到 Git 存储库:
git status 观察目前文件夹中文件的修改状态
git add <fichier> 可以将修改的文件上传到github,一旦上传就不可以退回去了
git add . 表示上传所有文件
git commit -m "xxx" "xxx"是每次上传的时候你留下的注释,以后可以回溯上传状态
5. 使用 git Push 将本地存储库中提交的更改推送到 GitHub 上的远程存储库。如果显示main找不到的话可以写master。这时可能会显示以下错误信息:
(base) pcia1@pcia1-P330:~/demo01_ws$ git push origin master
Username for 'https://github.com': xuezhennnn
Password for 'https://xuezhennnn@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/xuezhennnn/ros_learning.git/'
可以查看这篇文章debug,需要生成一个新的token,类似于账号密码的一个新的东西。
remote: Support for password authentication was removed on August 13, 2021 保姆级教程-优快云博客
如果显示下面的消息,那恭喜你成功把本地文件上传到你创建的github文件夹里面了。
(base) pcia1@pcia1-P330:~/demo01_ws$ git push origin master
Username for 'https://github.com': xuezhennnn
Password for 'https://xuezhennnn@github.com':
Décompte des objets: 276, fait.
Delta compression using up to 8 threads.
Compression des objets: 100% (248/248), fait.
Écriture des objets: 100% (276/276), 463.52 KiB | 7.48 MiB/s, fait.
Total 276 (delta 103), reused 0 (delta 0)
remote: Resolving deltas: 100% (103/103), done.
To https://github.com/xuezhennnn/ros_learning.git
* [new branch] master -> master