前提:
需要在windows下注册git环境变量,这一步骤网上有,推荐这位博主的:链接: link
1.注册github
这个没什么好说的,使用edge进行翻译过后直接注册即可
- 上边带日文的部分就是翻译。
2.注册完成之后,需要对GitHub新建一个repository
- 这里只需要填写repository name(库名称)和Descripition(库介绍)
- 分别填写这三步即可。
- 接着就会给出提示的代码
3.随便创建一个文件夹,然后进入到这个文件夹。
- 这里使用的是vscode里面的终端
powershell
。 - 首先进入你需要进入的文件夹
- 创建新的文件夹:
mkdir repository
cd repository
- 紧接着,将你需要的文件复制到
repository
主目录之下,此处手动操作即可。 - 接下来就是跟着github网站提示来:
git init
- 此时需要注意的是,之前你所添加的上传文件中不得出现文件夹自带的.git文件,这个文件一般是隐藏状态,需要点击查看隐藏文件夹才可以。
- 确保以上步骤正确的话,就可以着手接下来的代码
git add .
- 这段代码解释是添加你之前的文件到本地git中,"."代表所有文件。
- 接下来就是初次将本地文件和github在线关联:
这段代码可以直接复制网站上的:git remote add origin https://github.com/xxx/001.git
, - 在做完这个事情以后,使用
git remove
检查是否正常,一般正常会出现origin
,这就即将大功告成了。
接着进入repository
目录下面的.git
文件夹,这里面会有一个config
文件,使用记事本(Notepad++
)打开即可。Notepad++下载地址https://notepad-plus-plus.org/。
修改config文件
在 文件最前沿添加:
[user]
email=you@example.com
name=username
回到终端
输入下面的命令:
git config --global http.sslVerify "false"
- 不进行这一步会出现安全检查不通过。
- 接着输入:
git push -u origin master
第一次使用的时候需要添加-u,之后再使用时,使用以下代码即可。
git push origin master
之后在github上会弹出授权申请,点击authorization即可完成,之后刷新界面就ok了。
本人实践操作
PS E:\> mkdir A
目录: E:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2022/9/10 星期六 21:11 A
PS E:\> cd A
PS E:\A> mkdir learngit
目录: E:\A
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2022/9/10 星期六 21:12 learngit
PS E:\A> cd learngit
PS E:\A\learngit> git remote add origin https://github.com/3192575523/vscode_c_setting.git
fatal: not a git repository (or any of the parent directories): .git
PS E:\A\learngit> git remote add origin https://github.com/3192575523/vscode_c_setting.git
fatal: not a git repository (or any of the parent directories): .git
PS E:\A\learngit> git init
Initialized empty Git repository in E:/A/learngit/.git/
PS E:\A\learngit> git remote add origin https://github.com/3192575523/vscode_c_setting.git
PS E:\A\learngit> git remote
origin
PS E:\A\learngit> git push origin master
error: src refspec master does not match any
error: failed to push some refs to 'https://github.com/3192575523/vscode_c_setting.git'
PS E:\A\learngit> git push -u origin master
error: src refspec master does not match any
error: failed to push some refs to 'https://github.com/3192575523/vscode_c_setting.git'
PS E:\A\learngit> git commit -m "first commit"
Author identity unknown
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'Administrator@WIN-QEUHG51F954.(none)')
PS E:\A\learngit> git push origin master
error: src refspec master does not match any
error: failed to push some refs to 'https://github.com/3192575523/vscode_c_setting.git'
PS E:\A\learngit> git push origin main
error: src refspec main does not match any
error: failed to push some refs to 'https://github.com/3192575523/vscode_c_setting.git'
PS E:\A\learngit> git pull origin master
fatal: couldn't find remote ref master
PS E:\A\learngit> touch README
touch : 无法将“touch”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
所在位置 行:1 字符: 1
+ touch README
+ ~~~~~
+ CategoryInfo : ObjectNotFound: (touch:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS E:\A\learngit> git commit -m "init"
Author identity unknown
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'Administrator@WIN-QEUHG51F954.(none)')
PS E:\A\learngit> git add .
error: 'C_Program/' does not have a commit checked out
fatal: adding files failed
PS E:\A\learngit> fit init
fit : 无法将“fit”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
所在位置 行:1 字符: 1
+ fit init
+ ~~~
+ CategoryInfo : ObjectNotFound: (fit:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS E:\A\learngit> git init
Reinitialized existing Git repository in E:/A/learngit/.git/
PS E:\A\learngit> git add .
error: 'C_Program/' does not have a commit checked out
fatal: adding files failed
PS E:\A\learngit> git init
Initialized empty Git repository in E:/A/learngit/.git/
PS E:\A\learngit> git add .
error: 'C_Program/' does not have a commit checked out
fatal: adding files failed
PS E:\A\learngit> git rm -r -f --cached
fatal: No pathspec was given. Which files should I remove?
PS E:\A\learngit> git add .
warning: in the working copy of 'C_Program/.vscode/tasks.json', LF will be replaced by CRLF the next time Git touches it
PS E:\A\learngit> git commit -m
error: switch `m' requires a value
PS E:\A\learngit> git remote add origin https://github.com/3192575523/vscode_c_setting.git
PS E:\A\learngit> git remote
origin
PS E:\A\learngit> git push origin master
error: src refspec master does not match any
error: failed to push some refs to 'https://github.com/3192575523/vscode_c_setting.git'
PS E:\A\learngit> git commit -m "first commit"
Author identity unknown
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'Administrator@WIN-QEUHG51F954.(none)')
PS E:\A\learngit> git config -- global user.name
error: key does not contain a section: global
PS E:\A\learngit> git commit -m "first commit"
[master (root-commit) 2494bcb] first commit
6 files changed, 136 insertions(+)
create mode 100644 C_Program/.vscode/c_cpp_propertise.json
create mode 100644 C_Program/.vscode/launch.json
create mode 100644 C_Program/.vscode/tasks.json
create mode 100644 C_Program/hello/main.c
create mode 100644 C_Program/hello/main.exe
create mode 100644 C_Program/main.exe
PS E:\A\learngit> git push origin master
fatal: unable to access 'https://github.com/3192575523/vscode_c_setting.git/': OpenSSL SSL_read: Connection was reset, errno 10054
PS E:\A\learngit> git config --global http.sslVerify "false"
PS E:\A\learngit> git push origin master
PS E:\A\learngit> git push -u origin master
warning: ----------------- SECURITY WARNING ----------------
warning: | TLS certificate verification has been disabled! |
warning: ---------------------------------------------------
warning: HTTPS connections may not be secure. See https://aka.ms/gcm/tlsverify for more information.
info: please complete authentication in your browser...
warning: ----------------- SECURITY WARNING ----------------
warning: | TLS certificate verification has been disabled! |
warning: ---------------------------------------------------
warning: HTTPS connections may not be secure. See https://aka.ms/gcm/tlsverify for more information.
Enumerating objects: 11, done.
Counting objects: 100% (11/11), done.
Delta compression using up to 8 threads
Compressing objects: 100% (10/10), done.
Writing objects: 100% (11/11), 20.14 KiB | 6.71 MiB/s, done.
Total 11 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/3192575523/vscode_c_setting.git
* [new branch] master -> master
branch 'master' set up to track 'origin/master'.
PS E:\A\learngit> git push -u origin master
- 中间有一大部分是因为没有配置好文件等造成的,希望能给大家提供参考。