3.6 KiB
3.6 KiB
Git操作记录
本文档记录了在仓库中执行的主要Git操作步骤和结果。
1. 初始化本地Git仓库
操作命令:
git init
执行结果:
Initialized empty Git repository in D:/工作/笔记/.git/
2. 设置远程仓库链接
操作命令:
git remote add origin https://git.tsama.cn/bb/BiJi.git
执行结果: 成功添加远程仓库引用
3. 添加并提交文件
操作命令:
git add .
执行结果:
warning: in the working copy of 'Demo1/GPIO.md', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'Demo1/demo.md', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'git/git操作.md', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'git/git流程..md', LF will be replaced by CRLF the next time Git touches it
提交命令:
git commit -m "初始化提交"
执行结果:
[master (root-commit) 5b02c1a] 初始化提交
4 files changed, 166 insertions(+)
create mode 100644 Demo1/GPIO.md
create mode 100644 Demo1/demo.md
create mode 100644 "git/git操作.md"
create mode 100644 "git/git流程..md"
4. 推送到远程仓库
操作命令:
git push -u origin master
执行结果:
Enumerating objects: 8, done.
Counting objects: 100% (8/8), done.
Delta compression using up to 16 threads
Compressing objects: 100% (8/8), done.
Writing objects: 100% (8/8), 3.64 KiB | 1.21 MiB/s, done.
Total 8 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
remote:
remote: Create a new pull request for 'master':
remote: https://git.tsama.cn/bb/BiJi/pulls/new/master
remote:
remote: . Processing 1 references
remote: Processed 1 references in total
To https://git.tsama.cn/bb/BiJi.git
* [new branch] master -> master
branch 'master' set up to track 'origin/master'.
5. 分支管理操作
查看分支状态
操作命令:
git branch -a
初始状态:
* master
remotes/origin/HEAD -> origin/main
remotes/origin/main
remotes/origin/master
尝试删除默认分支(失败)
操作命令:
git push origin --delete main
失败结果:
remote:
remote: error:
remote: error: branch main is the default branch and cannot be deleted
remote: error:
To https://git.tsama.cn/bb/BiJi.git
! [remote rejected] main (pre-receive hook declined)
error: failed to push some refs to 'https://git.tsama.cn/bb/BiJi.git'
更改本地远程HEAD引用
操作命令:
git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/master
通过Web界面更改默认分支
在Git服务器Web界面执行以下操作:
- 登录到Git服务器(https://git.tsama.cn)
- 进入BiJi仓库设置
- 将默认分支从main更改为master
成功删除远程main分支
操作命令:
git push origin --delete main
执行结果:
remote: . Processing 1 references
remote: Processed 1 references in total
To https://git.tsama.cn/bb/BiJi.git
- [deleted] main
6. 最终分支状态确认
操作命令:
git branch -a
最终状态:
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
总结
通过以上操作,我们成功地:
- 初始化了本地Git仓库并与远程仓库关联
- 提交并推送了初始代码
- 成功将远程仓库结构简化为仅保留master分支
现在仓库结构更加清晰,所有开发工作都将在master分支上进行。