欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

git创建本地仓库,然后推送到github

程序员文章站 2022-07-13 17:37:48
...

先决条件,本地有git,自己拥有github账号

生成ssh公钥

这次我是在windows上进行的,在linux上也是差不多的。
在git bash

$ ssh-****** -t rsa -C “[email protected]

一路回车也行,我是一路回车

到这里可以查看到刚刚生成的公钥

cat ~/.ssh/id_rsa.pub

把公钥配置到github上去

登录自己github, 打开setings > SSH and GPG keys > New SSH key

Title 按照自己爱好写,key就把 ~/.ssh/id_rsa.pub里面的内容全部复制进来

然后Add SSH key就好了

最后测试一下连通性

$ ssh -T [email protected]

The authenticity of host 'github.com (13.250.177.223)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,13.250.177.223' (RSA) to the list of known hosts.
Hi magicmshing! You've successfully authenticated, but GitHub does not provide shell access.

出现这样的信息则表示成功

准备一个本地git仓库

  • 创建一个本地仓库
    进入想要作为git仓库的文件夹,输入git init就把整个当前文件夹变成一个git仓库了
 $ git init
Initialized empty Git repository in E:/minipro/Tm/.git/
  • 把需要上传的文件或者文件夹放在暂存区
$ git add .
warning: LF will be replaced by CRLF in app.js.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in app.json.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in app.wxss.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in pages/index/index.js.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in pages/index/index.wxml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in pages/index/index.wxss.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in pages/logs/logs.js.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in pages/logs/logs.json.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in pages/logs/logs.wxml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in pages/logs/logs.wxss.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in project.config.json.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in utils/util.js.
The file will have its original line endings in your working directory.

. 是代表当前的全部文件和文件夹

  • 提交
$ git commit -m "first commit my wechat miniprogram"
[master (root-commit) d30833f] first commit my wechat miniprogram
 25 files changed, 293 insertions(+)
 create mode 100644 app.js
 create mode 100644 app.json
 create mode 100644 app.wxss
 create mode 100644 images/cloudy-bg.png
 create mode 100644 images/cloudy-icon.png
 create mode 100644 images/heavyrain-bg.png
 create mode 100644 images/heavyrain-icon.png
 create mode 100644 images/lightrain-bg.png
 create mode 100644 images/lightrain-icon.png
 create mode 100644 images/overcast-bg.png
 create mode 100644 images/overcast-icon.png
 create mode 100644 images/snow-bg.png
 create mode 100644 images/snow-icon.png
 create mode 100644 images/sunny-bg.png
 create mode 100644 images/sunny-icon.png
 create mode 100644 images/time-icon.png
 create mode 100644 pages/index/index.js
 create mode 100644 pages/index/index.wxml
 create mode 100644 pages/index/index.wxss
 create mode 100644 pages/logs/logs.js
 create mode 100644 pages/logs/logs.json
 create mode 100644 pages/logs/logs.wxml
 create mode 100644 pages/logs/logs.wxss
 create mode 100644 project.config.json
 create mode 100644 utils/util.js

推送到github

设置远程的起源

$  git remote add origin [email protected].com:XXXXX/XXX.git

然后提交就好

$ git push -u origin master
Enumerating objects: 33, done.
Counting objects: 100% (33/33), done.
Delta compression using up to 4 threads.
Compressing objects: 100% (31/31), done.
Writing objects: 100% (32/32), 92.32 KiB | 153.00 KiB/s, done.
Total 32 (delta 5), reused 0 (delta 0)
remote: Resolving deltas: 100% (5/5), done.
To github.com:magicmshing/Tm.git
   c4c56ce..0dbd8a6  master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

首次需要-u ,之后提交就不需要了,这一步就要完了

emmm,可能你会遇到坑吧?

我吧我遇到的一个坑给你看看,就是$ git push -u origin master这一步出错的。

相关标签: git github