Git 命令行
0、基础设置
1# 查看代理
2$ git config --global --get http.proxy
3$ git config --global --get https.proxy
4# 设置代理
5$ git config --global http.proxy http://[username:passwrod@]<ip or URL>:port
6$ git config --global https.proxy http://[username:passwrod@]<ip or URL>:port
7# 取消代理
8$ git config --global --unset http.proxy
9$ git config --global --unset https.proxy
10
11# 只代理github.com
12$ git config --global --get http.https://github.com.proxy
13$ git config --global --get https.https://github.com.proxy
14$ git config --global http.https://github.com.proxy http://[username:passwrod@]<ip or URL>:port
15$ git config --global https.https://github.com.proxy http://[username:passwrod@]<ip or URL>:port
16$ git config --global --unset http.https://github.com.proxy
17$ git config --global --unset https.https://github.com.proxy
18# push设置
19$ git config --global push.default simple
1、项目
1.1 克隆项目
1$ git clone https://xxxx@bitbucket.org/xxxx/xxxx.git
2# or
3$ git clone git@github.com:xxxxx/xxxxx.git
4# 克隆指定分支,到指定目录
5$ git clone -b <branch> <repo> <path>
6
7$ git config user.name "Your Name"
8$ git config user.email you@example.com
9
10
11
1.2 推送新项目到github
先在githubh上创建好项目
1$ git init
2$ git add .
3$ git status -s
4$ git config user.name "Your Name"
5$ git config user.email you@example.com
6$ git commit --amend --reset-author
7$ git commit -m "first commit"
8$ git remote add origin git@github.com:Youname/repo_name.git
9$ git push -u origin master
1.3 导出
1$ git archive --format zip -0 \ # 使用zip格式,不压缩
2 --output output.zip \ # 输出的文件名
3 --remote git@github.com:Cuile/NMP.git \ # 远程项目地址
4 master \ # 分支名
5 ./ # 输出到当前目录
2、分支
2.1 本地分支操作
1# 拉取
2$ git pull
3# 强制覆盖本地分支
4$ git fetch --all
5$ git reset --hard origin/<branch>
6$ git pull
7
8# 推送
9# 查看本地项目状态
10$ git status -s
11# 添加文件 | 添加目录 | 添加所有内容
12$ git add < file | dir | . >
13# 删除 add 的文件
14$ git rm [-r] --cached <file | .>
15# 提交已修改的文件,但不提交未跟踪的文件
16$ git commit -m <"message"> --untracked-files=no
17# 提交已删除的文件
18$ git commit -m <"message"> -a
19# 推送到远程库
20$ git push
21
22# 创建分支
23# 只创建一个分支
24$ git branch <branch-name>
25# 创建一个分支并切换到该分支
26$ git checkout -b <branch-name>
27
28# 查看分支
29$ git branch -a
30
31# 切换分支
32$ git checkout <branch name>
33
34# 删除分支
35$ git branch -d <branch name>
36
37# 发布本地分支
38$ git push <远程主机名> <本地分支名>:<远程分支名>
39
40# 合并分支
41# 将 a 分支合并到 b 分支
42$ git checkout b
43$ git merge a
44$ git push
2.2 远程分支操作
1# 拉取
2$ git fetch origin <branch>
3$ git checkout -b <branch> origin/<branch>
4$ git pull origin <branch>
5
6# 查看远程仓库地址
7$ git remote -v
8
9# 更新远程分支列表
10# 如果你的 remote branch 不是在 origin 下,把 origin 换成你的名字
11# --prune 删除远程已经删除的分支
12$ git remote update origin --prune
2.3 删除本地文件后,从远端重新拉取最新版本
git提示: up-to-date. 但未从远端得到文件
1# 1 查看本地分支是否发生变化
2$ git branch -a
3
4# 2 如本地库处于另一个分支中,需将本地分支重置回原分支
5$ git checkout <branch name>
6$ git reset --hard
7
8# 3 如本地分支没有变化,则强行 pull 覆盖本地文件
9$ git fetch --all
10$ git reset --hard origin/<branch name>
11$ git pull
2.4 重命名分支
1# 查看本地分支
2$ git branch -a
3# 切换到要重命名的分支
4$ git checkout <branch-name>
5# 重命名分支
6$ git branch -m <new branch-name>
7# 上传新分支
8$ git push origin -u <new branch-name>
9# 删除原分支
10$ git push origin --delete <old branch-name>
2.5 更改本地分支对应的远程分支
1# dev为本地分支,origin/master为远程分支
2$ git branch --set-upstream-to=origin/master dev
3# or
4$ git branch --set-upstream dev origin/master
3、标签
1# 查看现有的标签
2$ git tag
3
4# 给最新的提交打标签
5$ git tag 1.0
6
7# 推送所有标签
8$ git push --tags
相关专栏文章
- Nuitka 参数列表
- ProxmoxVE 配置 DHCP 网络
- Windows防火墙配置
- 在 CentOS 上部署 NetBIOS
- Tmux 命令
- 配置 CentOS 7 的 CT 容器
- Ncftp 使用手册
- Centos7 安装 Postgresql
- 在CentOS中安装 Laravel 框架
- 虚拟主机安装 Laravel 框架
- snap 设置代理
- Rime输入法设置
- Windows系统配置
- 灌篮高手大结局(全国大赛后) 下
- 灌篮高手大结局(全国大赛后) 上
- VScode 在 Docker 容器内开发
- VSCode 配置 Python 开发环境
- ProxmoxVE 配置 BBR
- ProxmoxVE 关闭订阅提示
- Linux 文本文件操作
- Deepin 使用远程桌面
- Hyper-V 下设置 Deepin 分辨率
- VsCode 使用 Remote SSH 连接 Alpine Linux
- Alpine Linux 安装 Bash
- frp安装配置
- Alpine Linux 配置
- screen 命令
- Systemd 系统工具命令指南
- ProxmoxVE 命令行
- Hyper-V 环境下给 CentOS 磁盘扩容
- Hyper-V 下设置 Ubuntu 分辨率
- Windows 10 家庭版安装 Hyper-V
- Hyper-V 网络设置
- Docker Compose 指令
- 使用 SSH 连接 Github
- Alpine Linux 安装 Docker
- Alpine Linux 网络设置
- 虚拟机安装 Alpine Linux 3.16
- 山克 UPS 安装手册
- Git 命令行
- 使用 Snap 安装 Docker
- (CentOS 7 | Rocky 9) 安装 Docker
- 修复 ProxmoxVE RRD 错误
- FFmpeg脚本
- Yum 版本库管理
- Linux系统内核升级
- iptables 配置
- ProxmoxVE 配置 NAT 网络
- MySQL 数据操作
- 使用 nmcli 配置网络
- 使用 sed 命令操作
- Linux 系统初始化配置
- Github使用Hugo生成Blog
- Docker使用命令
- About
- Search