一、本地项目初始化上传git
1、初始化本地项目
git init
2、添加文件到暂存区
git add <文件名> 或 git add .
3、提交文件到本地仓库
git commit -m "提交说明"
4、关联远程仓库
git remote add origin <远程仓库URL>
5、推送本地仓库到远程仓库
git push -u origin master
6、git在push推送时,报错提示信息如下:
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
原因:是由于本地和远程仓库两者代码文件不同步,因此需要先pull,进行合并然后再进行push
解决方法:
(1)先使用pull命令:
git pull --rebase origin master
如果存在冲突,解决完冲突后,使用命令git rebase --continue,可以将代码合并到之前操作时的分支
(2)再使用push命令:
git push -u origin master
二、分支管理
1、创建新分支
git branch <分支名>
2、切换到指定的分支
git checkout <分支名>
3、将指定的分支合并到当前分支
git merge <分支名>
三、回退版本
git reset <版本号>