GitLab / sourcetree 使用

1,077 阅读2分钟

1.Sourcetree 的使用

在使用中选中了Local -> New... -> clone from URL

image.png

出现提示: 这是一个无效的源路径/URL This is not a valid source path/URL 记得检查:

  • 是否开启了Git

image.png

我选择了 Use System Git,重新添加路径就可以克隆远程代码了。 突然有一天就提交不上代码了,报如下错误,而且此时添加远程repo也报错是无效URL

sourcetree Failed to connect to gitlab.com port 443 after 75043 ms: Operation timed out

这两种情况都是修改Git Version可以解决。

2.gitLab的使用

GitLab官网登录

a.创建一个新的project New project,和已有工程名称相同

image.png

注意 Project slug会自动变成小写,为了和本地的工程名称保持一致,需要注意是否和Project name保持一致。接下来的操作主要因为BLM运动,2020年10月1日起 默认的master 改为了 main

git branch  // 查看本地所有分支
git checkout main  // 切换本地分支
git branch -d locationBranchName  // 删除本地分支
git push origin --delete remoteBranchName  //删除远程分支
git branch -m oldName newName //修改本地的分支名称
  • 直接上传已有本地项目 - 需要删除工程本身的 隐藏 .git 文件,不然会提交失败 关键git 命令
cd 当前本地项目文件夹
git init
git remote add origin 远程仓库地址https
git add .
git commit -m '修改文案'
git pull --rebase origin main  // 必须使用main 不再使用master --fu*k BLM
git push -u origin master  // 此处使用mater新建一个origin下的远程分支
  • Clone 远程项目到本地, 原有的工程.git可删除,现有的拉下远程的.git可不删除
cd 到当前想放置工程的文件夹
git clone 项目远程地址
git init 
git add .
git commit -m '修改文案'
git pull --rebase origin main
git push -u origin main  // 此处就是main ,本地的分支也是main推到远程仓库当然是main

参考