共计 861 个字符,预计需要花费 3 分钟才能阅读完成。
解决本人的用户名和邮箱
# 查看本人的用户名和邮箱 | |
git config --list | |
# 配置你的用户名和邮箱 | |
git config --global user.name 用户名 | |
git config --global user.email 邮箱 | |
# 配置你的用户名和邮箱(想批改)git config --global --replace-all user.name 用户名 | |
git config --global --replace-all user.email 我的邮箱 |
创立 Git 仓库
mkdir [project_name] | |
cd [project_name] | |
git init | |
touch README.md | |
git add README.md | |
git commit -m "first commit" | |
git remote add 近程仓库别名 [remote] | |
git push -u 近程仓库别名 "master" |
拉取近程仓库到本地
# 拉取近程仓库默认分支的代码 | |
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 |
正文完