git使用指南——以gitlab为例

注册gitlab

自行注册

新建项目

选择新建一个空白的项目

上传项目

clone项目地址到本地

执行完之后,会在目录下生成如下内容:

进入里面,选择.git,要上传的内容(资料或代码复制到该目录下):

选择上传分支

如果不选择上传的分支,会默认上传到master分支上面

新建分支
  1. 打开项目页面。
  2. 点击左侧导航菜单中的"Repository"(或者类似名称)选项。
  3. 在主界面上方的工具栏中,点击"Branches"按钮。这将显示当前存在的所有分支列表。
  4. 在右上角的输入框中输入要创建的新分支的名称。确保该名称不与已经存在的分支重复。
  5. 如果需要基于现有分支来创建新分支,则从下拉菜单中选择相应的分支作为基础。否则,默认情况下会使用最新提交的分支作为基础。
  6. 点击"Create branch"按钮进行创建。
  7. GitLab将自动切换到新创建的分支并跳转到对应的文件视图。
  8. 此时,就可以在新分支上进行修改、添加或删除文件等操作了。

也可通过命令行建立,下面会说!

上传项目

先把仓库的内容同步到本地:

plsql 复制代码
git pull --rebase ori master

然后把本地内容推送上去:

plsql 复制代码
git push -u ori master

推送上去后,查看gitlab:

可以看到,内容已经推送上去了:

拉取项目

远程拉取

找到需要拉取的项目,然后复制对应的url,执行git clone +url 就可以了(最好提前选择好对应的存放目录)

分支

查看分支

git branch -v

创建分支

git branch 分支名

修改分支

修改分支其实就是增删查改分支上的内容,每次修改完之后,都得重新执行一次完整操作

--在 maste 分支上做修改

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ **vim hello.txt **

--添加暂存区

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ **git add hello.txt **

--提交本地库

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ **git commit -m "my forth commit" hello.txt **

master f363b4c\] my forth commit 1 file changed, 1 insertion(+), 1 deletion(-) --查看分支 Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master) $ \*\*git branch -v \*\* hot-fix 087a1a7 my third commit (hot-fix 分支并未做任何改变) * master f363b4c my forth commit (当前 master 分支已更新为最新一次提交 的版本) --查看 master 分支上的文件内容 Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master) $ cat hello.txt hello git! hello atguigu! 2222222222222 hello git! hello atguigu! 3333333333333 hello git! hello atguigu! hello git! hello atguigu! hello git! hello atguigu! hello git! hello atguigu! hello git! hello atguigu! hello git! hello atguigu! hello git! hello atguigu! hello git! hello atguigu! hello git! hello atguigu! hello git! hello atguigu! hello git! hello atguigu! hello git! hello atguigu! hello git! hello atguigu! master test

切换分支

git checkout 分支名

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 **(master) **

$ **git checkout hot-fix **

Switched to branch 'hot-fix'

--发现当先分支已由 master 改为 hot-fix

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 **(hot-fix) **

$

--查看 hot-fix 分支上的文件内容发现与 master 分支上的内容不同

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 **(hot-fix) **

$ cat hello.txt

hello git! hello atguigu! 2222222222222

hello git! hello atguigu! 3333333333333

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

合并分支

git merge 分支名

**在 master 分支上合并 hot-fix 分支 **

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ **git merge hot-fix **

Auto-merging hello.txt

CONFLICT (content): Merge conflict in hello.txt

Automatic merge failed; fix conflicts and then commit the result.

指令汇总

**命令名称 ** 备注
git remote -v 查看当前所有远程地址别名
git remote add 别名 远程地址 起别名
git push 别名 分支 推送本地分支上的内容到远程仓库
git clone 远程地址 将远程仓库的内容克隆到本地
git pull 远程库地址别名 远程分支名 将远程仓库对于分支最新内容拉下来后与 当前本地分支直接合并
相关推荐
闲人编程2 小时前
Elasticsearch搜索引擎集成指南
python·elasticsearch·搜索引擎·jenkins·索引·副本·分片
先跑起来再说3 小时前
Git 入门到实战:一篇搞懂安装、命令、远程仓库与 IDEA 集成
ide·git·后端·elasticsearch·golang·intellij-idea
Dxy12393102164 小时前
深度解析 Elasticsearch:从倒排索引到 DSL 查询的实战突围
大数据·elasticsearch·搜索引擎
承渊政道6 小时前
Linux系统学习【Linux系统的进度条实现、版本控制器git和调试器gdb介绍】
linux·开发语言·笔记·git·学习·gitee
Doro再努力6 小时前
【Linux操作系统12】Git版本控制与GDB调试:从入门到实践
linux·运维·服务器·git·vim
Dxy12393102166 小时前
别再让 ES 把你拖垮!5 个实战技巧让搜索性能提升 10 倍
大数据·elasticsearch·搜索引擎
摇滚侠9 小时前
MAC IDEA GIT 提交区显示了几个不存在的目录
git·idea
城东10 小时前
Git使用[远程仓库远端的head比本地和提交的head旧,其他人拉不到最新代码]
git·head·远程仓库远端·比本地和提交的head旧·其他人拉不到最新代码
星辰_mya11 小时前
Elasticsearch线上问题之OOM
大数据·elasticsearch·搜索引擎
Elastic 中国社区官方博客11 小时前
使用 Groq 与 Elasticsearch 进行智能查询
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·全文检索