Featured image of post Git操作相关命令

Git操作相关命令

首次上传、设置用户名、更新提交等

第一次上传

1
2
3
4
git add .
git commit -m "first commit"
git remote add origin https://github.com/bmpi-dev/test.bmpi.dev.git
git push -u origin main

修改用户名信息

git 修改当前的project的用户名的命令为:git config --global user.name "Your Name";

git 修改当前的project提交邮箱的命令为:git config --global user.email [email protected];

设置完毕后,您可以用下面的命令来修正本次提交所使用的用户身份:

1
git commit --amend --reset-author

记住密码和用户名

为命令行创建一个口令

1
git config --global credential.helper store

然后需要做的就是在git push的时候

1
2
Username for 'https://github.com': xxxxx
Password for 'https://[email protected]': xxxx

这里的Password项目你将在github后台生成的access token 粘帖进去就行了

至于文件保存在哪里?

文件保存位置是/home/你使用的账户/

会在这个目录生成两个文件.gitconfig.git-credentials

之后你在linux终端里的操作就不会被验证程序打扰了。

使用git config --list查看已设配置

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
credential.helper=osxkeychain
credential.helper=store
user.name=xxx
user.email=xxxx
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
core.precomposeunicode=true
submodule.themes/tony.url=https://github.com/ThemeTony/hugo-theme-tony.git
submodule.themes/tony.active=true
remote.origin.url=https://github.com/xxxx.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*

新增更新操作

如果之后你要新增文章后上传也只需要执行:

1
2
3
git add .
git commit -m "update"
git push

add 之后可以回滚操作

1
git reset --mixed

更改默认主分支 main

如果在初始化git的时候,默认分支为master,需要更改为main时的情况。

1、切换分支

使用checkout命令指定 -b选项执行,可以创建分支并进行切换。

1
$ git checkout -b main

2、修改default分支

切换到main分支后,在github上将main分支设置default的分支

3、删除master分支

删除分支

1
git branch -D master

提交分支

1
git push origin :master

4、修改提交更新

1
2
git add .
git commit -m "commit to main"

合并分支

1
git merge

如果远程仓库main分支中无需要的内容,可进行强制push

1
git push origin +main
Licensed under CC BY-NC-SA 4.0
使用 Hugo 构建
主题 StackJimmy 设计