【个人向】常用的 Git 操作

拉取远程仓库到本地

# 拉取远程仓库默认分支的代码
git clone [remote]

# 拉取远程仓库指定分支的代码
git clone [remote] -b [branch]

更新 .gitignore 文件

# 删除所有文件缓存
git rm -r --cached .

# 把文件添加到本地暂存区
git add .

# 将本地暂存的修改提交到本地仓库
git commit -m 'update .gitignore'

# 将本地的分支版本上传到远程并合并
git pull && git push

创建新分支并提交到远程仓库

# 先查看一下当前所在分支
git branch 

# 创建本地分支并切换到新创建的分支
git checkout -b [branch]

# 把新建的分支 push 到远程,相当于创建一个远程分支
git push [remote] [branch]

合并分支

# 先切换到要进行合并的分支 a
git checkout [branch-a]

# 把分支 b 合并到分支 a
git merge [branch-b]

本地代码提交到远程仓库

# 把文件添加到本地暂存区
git add .

# 将本地暂存的修改提交到本地仓库
git commit '提交的描述文字'

# 将本地的分支版本上传到远程并合并
git pull && git push

你可能感兴趣的:(git)