Git常用方法、命令

35 阅读1分钟

Git常用方法、命令

查看用户名和email

$ git config user.name // 查看用户名
$ git config user.email // 查看邮箱

创建用户名和email

$ git config --global user.name "Your Name" // 创建用户名
$ git config --global user.email "email@example.com" // 创建邮箱

修改并提交

$ git add 文件名  // 添加单个文件
$ git add --all	// 添加全部文件
$ git commit -m "备注信息"
$ git push -u origin master	// 第一次提交
$ git push origin master	// 非第一次提交

分支管理

$ git pull	// 拉取最新内容
$ git fetch	// 获取远程仓库中本地没有的内容
$ git switch master	// 切换分支
$ git switch -c dev // 创建并切换到新分支,后面是分支名
$ git branch	// 查看当前分支
$ git remote update origin --prune // 将本地分支与线上分支同步(例:远程新建/删除分支,本地未同步)
$ git branch -D master // 删除分支,后面跟分支名
$ git merge dev // 合并指定分支到当前分支, 后面跟分支名

修改分支名

// 修改分支名
git branch -m oldName newName
// 删除远程分支
git push --delete origin oldName
// 上传新命名的本地分支
git push origin newName

创建SSH Key

$ ssh-keygen -t rsa -C "youremail@example.com" // 后面是邮箱

查看历史提交

$ git log