Blogger Information
Blog 75
fans 0
comment 0
visits 54675
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
小猿圈之git 的几个好用自定义命令
聆听的博客
Original
658 people have browsed it

现在越来越多人使用管理代码的仓库,github是其中的一种,github是程序员经常用的,github与git命令紧密相连,那git命令尤为重要,今天小猿圈老师带你学习一下git自定义好用的几个命令。

1. 把 checkout 的当前分支推送到远端
用法: 项目路径下执行: 文件名

实例

#!/bin/bash

#保存当前分支
curBranch=`git symbolic-ref --short -q HEAD`
git push origin $curBranch
git branch --set-upstream-to=origin/$curBranch $curBranch

运行实例 »

点击 "运行实例" 按钮查看在线实例

2. 分支合并, 指定分支合并到目标分支 (文件名:gmm)
用法: gmm 源分支 目标分支
例: gmm origin/master common_dev
没有参数直接 gmm 时, 合并 origin/maste 到当前分支

#!/bin/bash
#保存当前分支
curBranch=`git symbolic-ref --short -q HEAD`
#源分支
sourceBranch='origin/master'
if [ $1 ]; then
sourceBranch=$1
else
git fetch
fi
#目标分支
targetBranch="$curBranch"
if [ $2 ]; then
targetBranch="$2"
git checkout $targetBranch
#拉去最新代码分支
git pull
fi
#分支合并
echo
echo "分支 $sourceBranch 合并到 $targetBranch "
echo
git merge $sourceBranch -m "分支 $sourceBranch 合并到 $targetBranch "
#推送代码
git push
#切换回当前分支
git checkout $curBranch

3. 代码提交 (文件名:gci)
用法: 项目路径下执行: gci
包含了 git commit; git pull; git push

实例

#!/bin/bash

#git add .
description='默认注释-xxx'
if [ $1 ]; then
  description=$1
fi

git commit -m $description

git pull

git push

运行实例 »

点击 "运行实例" 按钮查看在线实例

4. 删除无用分支 (文件名:gbdr)
用法: gbdr 待删除分支名
说明: 当前不能位于待删除分支上

实例

#!/bin/bash

if [ $1 ]; then
    if [ $2 ]; then
        git branch $1 $2
    else
        git branch -d $1
    fi
  
  git push origin :$1
else
  echo "用法:"
  echo "gbdr 分支名称 --删除本地分支,远程分支"
  echo "gbdr -D 分支名称 --强制删除本地分支,远程分支"
  fi

运行实例 »

点击 "运行实例" 按钮查看在线实例

git命令就聊到这里,大家get到了吗?这些命令对我们仓库管理很重要,不会用git命令使用github的不是一个好程序员,希望大家看到小猿圈写的有所收获,希望能看到小编写的文章的朋友,真正能学到、领悟到。

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!