Git 相关操作

1,配置用户名和邮箱

复制代码
git config --global user.name "My Name"

git config --global user.email "myemail@example.com"

2,查看git设置,包含查看用户名和邮箱

复制代码
git config --list

3, 查看修改了哪些文件

复制代码
git status

4, 更新将要提交的内容

复制代码
git add <file>

5,提交更改

复制代码
git commit
# -m 与commit命令一起,指定提交信息
eg: git commit -m "version 1"

# -a commit 之前可以自动暂存每个更改的文件,此flag可以省去 git add

6, 创建branch

复制代码
git branch <branch-name> 
or:
git checkout -b <branch-name> 

#both create a branch but checkout switch to the new branch

7,推送到远端仓库

复制代码
git push -u origin HEAD

# Using HEAD is a "handy way to push the current branch to the same name on the remote". 
# In Git terms, HEAD (in uppercase) is a reference to the top of the current branch (tree).
# The -u option is just short for --set-upstream. This will add an upstream tracking reference for the current branch

参考:

Git - Recording Changes to the Repository

https://stackoverflow.com/questions/2765421/how-do-i-push-a-new-local-branch-to-a-remote-git-repository-and-track-it-too

相关推荐
无风听海6 小时前
git fsck 深度解析 Git 仓库的体检医生
git
洋仔13 小时前
Git 底层原理系列 · 第8讲 — HEAD 与 detached HEAD
git·开源
洋仔13 小时前
Git 底层原理系列 · 第4讲 — `git add` 与 `git commit` 底层做了什么
git·开源
猫咪老师QAQ15 小时前
基于 Git Flow 的团队协作与发布流程实践
git
caicai_xiaobai15 小时前
分享一个访问Git Hub的好方法
git
Joy T16 小时前
【Web3】跨链资金池与消息路由:CCIP 智能合约集成实战与权限收束
git·web3·node·智能合约·hardhat
難釋懷17 小时前
Nginx虚拟主机
git·nginx·github
moMo17 小时前
# Git 入门—代码仓库的使用
git·github
一路向北he18 小时前
git仓库创建新分支,上传文件
git
半个落月20 小时前
从零开始理解 Git 核心操作:告别单机开发的“原始时代”
git