为了账号安全,请及时绑定邮箱和手机立即绑定

我的Git的初步使用过程

标签:
前端工具

安装git

配置秘钥

打开git bash

输入ssh-keygen –t rsa –C "email"

完成后会在用户目录下建立.ssh目录,且生成秘钥文件id_rsa、id_rsa.pub

打开id_rsa.pub(公钥)文件,将内容全部复制(重要)

打开github,登录,进入setting->SSH and GPG keys,具体额参考文档:https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/

配置全局参数

打开Git bash

配置用户名: git config –global user.name "username"

配置邮箱: git config –global user.email "email"

git命令
  • 在本地当前目录下,将该目录初始化为一个git仓

git init;

  • 克隆个仓到本地

git clone [-b branch_name] git@github.com:git_username/pro_name.git

git remote
//给当前仓添加远程仓
git remote add repo_name git@github.com:git_username/pro_name.git
//修改远程仓在本地仓的命
git remote rename cur_repo_name new_repo_name
//移除仓
git remote remove repo_name
//查看远程仓
git remote -v
git [push|pull]
//将当前本地的分支(与远程分支同名)的推送到远程仓上
git push repo_name 远程分支
//将本地分支推送到远程分支上
git push repo_name 本地分支:远程分支
//删除远程仓上的分支
git push repo_name :远程分支

//从远程分支上拉取代码
git pull repo_name 远程分支
git基础命令
//切换分支
git checkout branch_name
git checkout -b local_branch_name [repo_name/branch_name]
//查看当前仓状态,如是否有文件修改
git status
//将变动的文件从工作区存放到暂存区
git add -A
//将暂存区的文件提交到仓里
git commit -m "commit注释"
//修改提交注释
git commit --amend
// 查看提交记录
git log
//查看分支
git branch
//修改本地分支名
git branch -m cur_branch_name new_branch_name
//删除本地分支
git branch -[d|D] branch_name
git stash
// 将修改的文件储藏起来,随时可以重新应用
git stash save "注释"
// 查看stash记录
git stash list
//将储藏的修改恢复到工作区里,但pop方式会取出stash@{0}并将其移除
git stash pop
// 将对应stash的number从储藏里获取出来,但不移除
git stash apply stash@{number}
//将对应stash的number从储藏里移除
git stash drop stash@{number}
git reset
//更改commit信息,但不覆盖工作区、暂存区的代码
git reset --soft 
//代码回退到两个提交前或10个提交前,^代表上一个提交,会更改工作区、commit的信息
git reset --hard [head^^|head~10]
git其他命令
//提取fetch远程分支数据
git fetch repo_name branch_name
//关联分支--set-upstream
git branch --set-upstream branch_name repo_name/branch_name
点击查看更多内容
3人点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
JAVA开发工程师
手记
粉丝
19
获赞与收藏
132

关注作者,订阅最新文章

阅读免费教程

感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消