Github使用

1. git基础操作

  • 基本代码
# 初始化本地仓库
git init

# 跟踪文件
git add -A # -A表示所哟新建的、修改的、删除的文件

# 提交
git commit -m "commit"

# 添加远程仓库
git remote add origin http://xxx.git

# 下拉远程分支到本地
git pull --rebase origin main:master 

# 推送本地分支到远程
git push -u origin master:main

:如果新建远程仓库时勾选了创建README.md的选项,则需要先pullpush

  • 如果大文件没有上传成功
# 从缓存区删除大文件
git rm --cached <file> 

# 恢复最近的commit
git commit --amend -CHEAD

# 提交
git commit -m "commit"

# 推送
git push -u origin master

# 用LFS上传大文件
git lfs install

# 跟踪大文件
git lfs track <file>

git add .gitattributes

git add <file>

git commit -m "commit"

git push # 不要用git push -u origin master

3. git高阶操作

  • 本地推送至远程
git push -u origin master:[<branch>]
  • 远程下拉到本地
git pull --rebase origin <branch>[:master] 
  • 本地强制覆盖远程
git push -f origin master
  • 远程强制覆盖本地
git fetch <branch>
git reset --hard origin/<branch>
  • 合并commit
git rebase -i HEAD~2
  • 合并分支
git merge --no-ff <branch>
  • 版本回退
git reset [--soft | --mixed | --hard] HEAD~1 # HEAD~1表示HEAD之前的一个版本
git reset [--soft | --mixed | --hard] commit-id 

3. git设置

  • 账号密码设置
git config --global user.name "name"

git config --global user.email "name@gmail.com"

git config --global -l

git config --global credential.helper store

其中–global表示本电脑所有仓库都使用这个配置

  • 代理设置
# 设置代理
git config --global http.proxy http://127.0.0.1:7890
git config --global https.proxy http://127.0.0.1:7890

# 取消代理
git config --global --unset http.proxy
git config --global --unset https.proxy

4. 其他资源

  • 常用命令速查表
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值