Git 切换至master分枝

1.git代码克隆
$ git clone https://......
2.拉取代码
$ git pull (origin master)
3.代码推送
$ git add .
$ git commit -m "提交信息"
$ git push (origin master)

4.本地新建一个分支
$ git fetch
$ git checkout -b (本地名(一般与线上分枝名一致)) origin/线上分枝名

5.本地分支切换到主分支(master)
$ git checkout master

6.本地分支合并到主分支(先切换到主分支master上)
$ git merge 本地分支名

7.查看当前分支
$ git branch -a

8.新建项目推到(git)
本地初始化一个项目
首先,你需要执行下面两条命令,作为 git 的基础配置,作用是告诉 git 你是谁,你输入的信息将出现在你创建的提交中。
git config --global user.name "你的名字或昵称"git config --global user.email "你的邮箱"

然后在你的需要初始化版本库的文件夹中执行:
git init git remote add origin <你的项目地址> //注:项目地址形式为:https://gitee.com/xxx/xxx.git或者 [email protected]:xxx/xxx.git

这样就完成了一次版本你的初始化。
如果你想克隆一个项目,只需要执行:
git clone <项目地址>

完成第一次提交
进入你已经初始化好的或者克隆项目的目录,然后执行:
git pull origin master<这里需要修改/添加文件,否则与原文件相比就没有变动>git add .git commit -m "第一次提交"git push origin master

然后如果需要账号密码的话就输入账号密码,这样就完成了一次提交。
此时,你可以在你的个人面板、项目主页查看到你的提交记录,例如:[https://gitee.com/oschina/git-osc/commit/f3dd1c5bae48fa4244e2595a39e750e5606dd9be](https://gitee.com/oschina/git-osc/commit/f3dd1c5bae48fa4244e2595a39e750e5606dd9be](https://gitee.com/oschina/git-osc/commit/f3dd1c5bae48fa4244e2595a39e750e5606dd9be](https://gitee.com/oschina/git-osc/commit/f3dd1c5bae48fa4244e2595a39e750e5606dd9be)
按照本文档新建的项目时,在码云平台仓库上已经存在 readme 文件,故在提交时可能会存在冲突,这时您需要选择的是保留线上的文件或者舍弃线上的文件,如果您舍弃线上的文件,则在推送时选择强制推送,强制推送需要执行下面的命令:
git push origin master -f

如果您选择保留线上的 readme 文件,则需要先执行:
git pull origin master

你可能感兴趣的:(Git 切换至master分枝)