Git 常用命令及进阶

在工作中,最多用的代码管理工具就是git,接下来分享一些git的常用命令:

1. git clone

这个命令没啥多说的,获取开源的源代码或者组内的project

git clone ...

2. git remote

git remote -v

通过这个命令,你可以得到当前repo所指向的远端repo,一般是 fetch 和 push两个。

origin  https://github.com/qcl006007/chat-vue.git (fetch)
origin  https://github.com/qcl006007/chat-vue.git (push)
  • 增加 一个remote
git remote add remote_name remote_url
  • 移除remote
git remote remove remote_name
  • 设置新的url
git remote set-url remote_name new_remote_address

3. git branch

使用git分支的好处在于多人协作的时候,可以避免大量的冲突。

  • 分支信息
git branch

通过这个命令,可以拿到当前repo的active分支,和有哪些分支。

  master
  pr/fix_bug
  pr/new_compare
* pr/use_slotname
  • 创建新分支
git branch new_branch(branch_name)

注意,如果使用这种方式创建新分支,那么active branch仍然是当前分支。

git branch pr/show_demo
git branch
  master
  pr/fix_bug  
  pr/new_compare
  pr/show_demo
* pr/use_slotname

如果想在创建新分支的同时切到另一个分支去工作,可以使用:

git checkout -b branch_name

删除本地分支,可以使用

git branch -D branch_name

4. git merge

git checkout base_branch
git merge new_branch

5. git handle conflict

<<<<<<<< HEAD
...
...
========
...
...
>>>>>>>> new_branch

通常有conflict的地方会有如下的显示,如果使用的是 vscode, visual studio等成熟的开发工具也会有冲突的提示。

6. git pull

同步最新的远端代码

7. git push

提交分支代码到远端仓库。

当然git的操作远不止这些,git还有好多实用的命令,类似 git stash, git commit, git revert, 等等。
接下来会继续介绍git的命令。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值