俗话说得好:
你有一个苹果,我有一个苹果,我们交换之后每个人还是只有一个苹果;
但是你有一个网站,我有一个网站,我们交换之后每个人就有了两个网站。
教程也是如此,因此整理了gitlab命令及常见bug,如下所示:
- 克隆
git clone 地址
- 更新本地仓库(进入仓库文件夹内执行)
git pull origin master
- 上传
gitlab上传之前必须设置ssh,方法如下:
cd ~/.ssh/
git config --global user.name "用户名"
git config --global user.email "邮箱"
ssh-keygen -t rsa -C "邮箱"
然后返回官网,依次点击头像->settings->SSH Keys
,把id_rsa.pub
(位于C:/users/administrator/.ssh/
)里的内容粘贴到gitlab
密钥中,接着执行
git config --global user.name ""
git config --global user.email ""
git init
git remote add origin 项目地址
git add .
git commit -m "程序源代码"
git push -u origin master
(更改后重新上传仅需要以上三行代码)
- 切换分支
git checkout 分支名
- 错误解决:
- 切换分支时报错
error: pathspec 'develop' did not match any file(s) known to git.
,执行命令:
输入账号和密码,正确之后即可切换分支,如果不幸输入错误,提示git fetch
fatal: Authentication failed for 'http:xxxx.git/'
,则执行以下语句:git config --system --unset credential.helper
- 上传文件到master分支报错
You are not allowed to push code to protected branches on this project. To gitlab.xxx-inc.com:sources/xxxx.git ! [remote rejected] master -> master (pre-receive hook declined)
,这是因为gitlab默认为master分支设置了保护,点击这个方法即可解决 - 报错
hint: Waiting for your editor to close the file... 'D:/Program\ Files\ x86x86/Sublime\ Text\ 2/sublime_text.exe' -n -w: D:/Program\ Files\ x86x86/Sublime\ Text\ 2/sublime_text.exe: No such file or directory
,主要是因为原先的默认编辑器移动了位置或者卸载了所以程序找不到,执行以下命令:
git config --global core.editor "'你的默认编辑器的位置,这里为S:/softwareinstall/Sublime Text 3/sublime_text.exe' -w -n"
alias subl="你的默认编辑器的位置,这里为S:/softwareinstall/Sublime Text 3/sublime_text.exe' -w -n"
- 切换分支时报错
网友评论