git 基础使用流程

git to use.

0.git schematic graph.

workspacetion
fetch/clone
push
checkout
pull
add
commit
Workspace
coding/edit
Remote
Repository
index/stage
  • Remote:远端仓库
    • fetch/clone -f:拉取或克隆
    • merge -f:合并分支
    • pull -f:拉取远程分支、合并本地分支
  • Repository:本地仓库
    • push -f:推送到远端、合并远端分支
    • checkout -b:新建并切换分支
    • branch -r/-b:查看远端分支/新建本地分支
  • index/stage:暂存区
    • commit -m:提交
  • workspace:工作区
    • add:暂存

1.system to configure.

  • windows—Git Bash.
  • linux—terminal.

00.配置用户名邮箱.

git config --global user.name "Your Name"
git config --global user.email "email@example.com"

01.配置公钥.

sudo apt-get install openssh-server
mkdir .ssh
cd .ssh
ssh-keygen -t username_azuregit_rsa
cat username_azuregit_rsa.pub
# 此处以gitlab为例
copy key into Login--user--settings--ssh keys--add key
cd .ssh
vim config  
# 此处可配置多个ssh key
eg:
#gitee
host gitee.com
         user kuanghl
         hostname ip_address
         port port_number
         identityfile ~/.ssh/gitee_id-rsa
# gitlab
Host gitlab.com
         HostName gitlab.com
         PreferredAuthentications publickey
         IdentityFile ~/.ssh/gitlab_id-rsa
# github
Host github.com
         HostName github.com
         PreferredAuthentications publickey
         IdentityFile ~/.ssh/github_id-rsa
# 参数解析
# Host : Host可以看作是一个你要识别的模式,对识别的模式,进行配置对应的的主机名和ssh文件.
# HostName : 要登录主机的主机名ip.
# User : 登录名.
# Port : 端口.
# IdentityFile : 指明上面User对应的identityFile路径.

2.git command and using process.

00.本地仓库初始化.

将这个目录当成自己本地仓库。

git init

01.clone project or merge code.

# case 0 new
git clone shh_address/http_address

# case 1 new merge old
# case 00 新建临时分支branch_name,进行拉取远端分支base_branch到branch_name, 
比对本地master分支与刚拉取分支的差异,合并拉取分支到本地分支中去,删除branch_name.
git branch branch_name
git fetch origin base_branch : branch_name
git diff branch_name
git merge branch_name
git branch -d branch_name
# case 01 拉取远端base_branch,比对其与本地master分支的差异,将远端分支合并到本地分支中去.
git fetch origin base_branch
git log -p branch_name..origin/base_branch
git merge origin/base_branch
# case 02 直接拉取远端分支base_branch合并到本地分支中去.
git pull origin base_branch

02.create or delete branch.

# case0 新建并切换到branch_name分支
git checkout -b branch_name
# case1 基于远端base_branch创建并切换到新分支branch_name
git checkout -b branch_name origin/base_branch
# case2 两步走
git branch branch_name 
git checkout branch_name

# 新建本地分支推送到远端,然后将本地分支与远端分支关联,查看远端分支
# 关联则是以后的push/pull/fetch操作都是对远端分支branch_name进行
git checkout -b branch_name
git push origin branch_name 
git branch --set-upstream-to=origin/branch_name  
git branch -a  

# 删除本地分支
git branch -d branch_name
# 删除远端分支
git push origin --delete branch_name

03.enter workspace.

# 开始编写和修改代码
code .
vim file_name
...and so on

04.code compare and commit.

# 将所有修改代码暂存,提交,推送到远程分支base_branch
git add .
git commit -a -m 'notes'
git push
or git push origin base_branch
or git push origin branch_name : branch_name 

05.recovering disaster accidental code.

# 查看版本回退
git log
git reset --hard HEAD^   注:***(^个数代表回退版本个数)
or git reset --hard HEAD~3   注:***(回退到前3个版本)
or git reset --hard HEAD id  注:***(回退到指定id版本) 

06.check branch information.

# 查看分支来源
git remote -v
# 查看远端分支
git branch -r
git branch -a
# 查看当前分支版本信息
git log
# 查看当前分支状态
git status

3.git for development collaboration.

00.develop coarse drawing.

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值