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

相关推荐
jiayong233 小时前
Git 核心概念:Tag 与 Branch 的本质区别
git
Serene_Dream6 小时前
git 合并冲突的分支
git
我是一只puppy7 小时前
使用AI进行代码审查
javascript·人工智能·git·安全·源代码管理
玄同7657 小时前
Git常用命令指南
大数据·git·elasticsearch·gitee·github·团队开发·远程工作
十步杀一人_千里不留行11 小时前
Git提交前ESLint校验实践(Husky + lint-staged)
git·github
hh随便起个名13 小时前
适合小白的git的基础使用方法
git
我会一直在的14 小时前
Devps持续集成
git·ci/cd
CoderJia程序员甲15 小时前
GitHub 热榜项目 - 日榜(2026-02-08)
git·ai·开源·llm·github
Serene_Dream16 小时前
git 常用命令
git
jiayong2316 小时前
Detached HEAD 状态详解
git