1.在本地新建一个分支
git checkout -b test1
1.1同步远程分支到本地
1.2 同步代码: git pull
2.Git add *,指定提交的文件,如果为 * 则提交所有文件
3.Git commit -m ‘提交的注释’
4.提交本地分支到远程分支
git push origin (远程分支名称):(本地分支名称)
git push origin image_sse_smartb
5.切换分支
git checkout master
6.合并本地分支,将本地开发的dev分支合并到本地main分支
git switch main
git merge dev
7. 打包指定分支的代码
# 打包 main分支的代码 为zip包
git archive -o last.zip main
8. 拉取远程新分支并切换到该分支
整理了五种方法,我常用最后一种,这五种方法(除了第4中已经写了fetch的步骤)执行前都需要执行git fetch来同步远程仓库
(1)git checkout -b 本地分支名 origin/远程分支名
(2)git checkout --track origin/远程分支名 (这种写法是上面的简化版,效果完全一样)
(3)git checkout -t origin/远程分支名(这种写法是2的简化版)
(4)fetch指定的一个分支:git fetch [repo] [remote_branch_name]:[local_branch_name]
git checkout [local_branch_name]
(第一行的:[local_branch_name]如果不写,则本地新建的分支名默认与远程分支名相同)
(5)git fetch 获取远程所有分支
git branch -r 可以看到所有远程分支,假设有一个分支叫origin/mybranch
git checkout mybranch即可,会在本地新建一个同名分支,并与该远程分支关联
(git checkout origin/mybranch 会进入detached head状态,不会在本地新建分支,不要这样写)
附:
-
git branch #列出本地所有的分支
-
There is no tracking information for the current branch. 问题的解决方式:
原因:新建的分支由于没有指定远程对应的分支,在执行 git pull 的时候回报错:
在执行git pull的时候,提示当前branch没有跟踪信息:
对于这种情况有两种解决办法,就比如说要操作master吧,一种是直接指定远程master:
git pull origin master
另一种方法是指定一下
git branch --set-upstream-to=origin/master master
git pull