最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】git中创建新分支并设置默认提交到新分支

Git crifan 3383浏览 0评论

git 创建分支并提交

‎leonardyp.github.io/git/git-创建分支并提交到远程/

Git 本地创建分支并提交远程分支 – 简书

git提交本地分支到远程分支 – springbarley – 博客园

Git – 分支的新建与合并

然后去操作:

➜  ucowsapp git:(master) git branch

* master

➜  ucowsapp git:(master) git checkout -b pure_web

Switched to a new branch ‘pure_web’

➜  ucowsapp git:(pure_web) git branch

  master

* pure_web

➜  ucowsapp git:(pure_web) git push origin pure_web

Total 0 (delta 0), reused 0 (delta 0)

To https://gitee.com/ucowsapp/ucowsapp.git

* [new branch]      pure_web -> pure_web

➜  ucowsapp git:(pure_web) git pull origin pure_web

From https://gitee.com/ucowsapp/ucowsapp

* branch            pure_web   -> FETCH_HEAD

Already up-to-date.

然后此时已经可以看到远程的git中已经有了对应分支了:

然后继续设置默认为此新建分支:

➜  ucowsapp git:(pure_web) git branch –set-upstream-to=origin/pure_web

Branch pure_web set up to track remote branch pure_web from origin.

➜  ucowsapp git:(pure_web) git branch –unset-upstream master

这样之后再去提交commit和push时,就自动上传到新建的分支上了:

<code>➜  ucowsapp git:(pure_web) ✗ git status
On branch pure_web
Your branch is up-to-date with 'origin/pure_web'.

Changes not staged for commit:
  (use "git add &lt;file&gt;..." to update what will be committed)
  (use "git checkout -- &lt;file&gt;..." to discard changes in working directory)

    modified:   package-lock.json
    modified:   package.json
    modified:   src/common/define.js
    modified:   src/components/header/index.js
    modified:   src/container/app.js
    modified:   src/container/functions/index.js
    modified:   src/store/store.js
    modified:   src/style/variables.less

Untracked files:
  (use "git add &lt;file&gt;..." to include in what will be committed)

    src/container/cowshed/cowshed-switch/

no changes added to commit (use "git add" and/or "git commit -a")
➜  ucowsapp git:(pure_web) ✗ git add *
The following paths are ignored by one of your .gitignore files:
build
node_modules
Use -f if you really want to add them.
➜  ucowsapp git:(pure_web) ✗ git status
On branch pure_web
Your branch is up-to-date with 'origin/pure_web'.

Changes to be committed:
  (use "git reset HEAD &lt;file&gt;..." to unstage)

    modified:   package-lock.json
    modified:   package.json
    modified:   src/common/define.js
    modified:   src/components/header/index.js
    modified:   src/container/app.js
    new file:   src/container/cowshed/cowshed-switch/index.js
    new file:   src/container/cowshed/cowshed-switch/style.less
    modified:   src/container/functions/index.js
    modified:   src/store/store.js
    modified:   src/style/variables.less

➜  ucowsapp git:(pure_web) ✗ git commit -m "1. add basic code for cowshed switch"
[pure_web a160dae] 1. add basic code for cowshed switch
10 files changed, 427 insertions(+), 49 deletions(-)
create mode 100644 src/container/cowshed/cowshed-switch/index.js
create mode 100644 src/container/cowshed/cowshed-switch/style.less
➜  ucowsapp git:(pure_web) git status
On branch pure_web
Your branch is ahead of 'origin/pure_web' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean
➜  ucowsapp git:(pure_web) git push
Counting objects: 21, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (18/18), done.
Writing objects: 100% (21/21), 3.78 KiB | 967.00 KiB/s, done.
Total 21 (delta 14), reused 2 (delta 2)
To https://gitee.com/ucowsapp/ucowsapp.git
   e6b1def..a160dae  pure_web -&gt; pure_web
➜  ucowsapp git:(pure_web)
</code>

可以看到,的确是:

commit时是在分支:On branch pure_web

push时从本地的分支上传到远端的分支:pure_web -> pure_web

转载请注明:在路上 » 【已解决】git中创建新分支并设置默认提交到新分支

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.161 seconds, using 22.12MB memory