如何创建新的分支并推送到gitLab远程仓库
用git clone 从仓库里拉取完代码之后,用visual studio code 打开
第一步: 使用 git branch 查看自己所在的分支
PS D:\work\work2\1.12.0\fast-finance-admin-web> git branch
* fast-finance-admin-web-1.11.0
master
第二步: 使用 git branch 需要创建的分支名 即可创建新的分支
PS D:\work\work2\1.12.0\fast-finance-admin-web> git branch fast-finance-admin-web-1.12.0
第三步:再次使用 git branch 查看分支 即可看到自己刚创建的分支
PS D:\work\work2\1.12.0\fast-finance-admin-web> git branch
* fast-finance-admin-web-1.11.0
fast-finance-admin-web-1.12.0
master
第四步:使用命令 git checkout 新分支名 切换到新分支所在位置
PS D:\work\work2\1.12.0\fast-finance-admin-web> git checkout fast-finance-admin-web-1.12.0
第五步:使用git pull 更新一下本地的代码 这时会提示无法拉取
PS D:\work\work2\1.12.0\fast-finance-admin-web> git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> fast-finance-admin-web-1.12.0
第六步:执行一下它提示的那一行代码 git branch --set-upstream-to=origin/<branch> fast-finance-admin-web-1.12.0 这个是自己创建的新分支名称
PS D:\work\work2\1.12.0\fast-finance-admin-web> git branch --set-upstream-to=origin/<branch> fast-finance-admin-web-1.12.0
error: the requested upstream branch 'origin/<branch>' does not exist
hint:
hint: If you are planning on basing your work on an upstream
hint: branch that already exists at the remote, you may need to
hint: run "git fetch" to retrieve it.
hint:
hint: If you are planning to push out a new local branch that
hint: will track its remote counterpart, you may want to use
hint: "git push -u" to set the upstream config as you push.
第七步:再执行它提示的代码 git push -u
PS D:\work\work2\1.12.0\fast-finance-admin-web> git push -u
fatal: The current branch fast-finance-admin-web-1.12.0 has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin fast-finance-admin-web-1.12.0
第八步:最后在执行 git push --set-upstream origin fast-finance-admin-web-1.12.0(这个是新创建的分支名称)
PS D:\work\work2\1.12.0\fast-finance-admin-web> git push --set-upstream origin fast-finance-admin-web-1.12.0
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote:
remote: To create a merge request for fast-finance-admin-web-1.12.0, visit:
remote: https://gitlab.meditrusthealth.com/finance/fast-finance-admin-web/merge_requests/new?merge_request%5Bsource_branch%5D=fast-finance-admin-web-1.12.0
remote:
To gitlab.meditrusthealth.com:finance/fast-finance-admin-web.git
* [new branch] fast-finance-admin-web-1.12.0 -> fast-finance-admin-web-1.12.0
Branch 'fast-finance-admin-web-1.12.0' set up to track remote branch 'fast-finance-admin-web-1.12.0' from 'origin'.
结果:最后到你的gitLab 仓库里看一下 就能看到刚创建的分支了