当前位置:   article > 正文

GitHub 创建分支 (branch) 并提交分支_git 新建branch

git 新建branch

1. Branch: master

git clone https://github.com/ForeverStrongCheng/dbscan_clustering_algorithm

strong@foreverstrong:~/darknet_work$ git clone https://github.com/ForeverStrongCheng/dbscan_clustering_algorithm
Cloning into 'dbscan_clustering_algorithm'...
Username for 'https://github.com': chengyq116@163.com
Password for 'https://chengyq116@163.com@github.com': 
remote: Enumerating objects: 33, done.
remote: Counting objects: 100% (33/33), done.
remote: Compressing objects: 100% (26/26), done.
remote: Total 33 (delta 6), reused 30 (delta 6), pack-reused 0
Unpacking objects: 100% (33/33), done.
Checking connectivity... done.
strong@foreverstrong:~/darknet_work$
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

在这里插入图片描述

2. git branch

git branch - 查看本地分支
git branch -r - 查看远程分支
git branch -a - 查看本地仓库和远程分支 (a 是 all 的简写)

strong@foreverstrong:~/darknet_work$ cd dbscan_clustering_algorithm/
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ 
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ git branch
* master
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ 
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ git branch -r
  origin/HEAD -> origin/master
  origin/master
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ 
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

3. git branch dbscan_dev - git checkout dbscan_dev

git branch dbscan_dev - 新建本地分支 dbscan_dev
git checkout dbscan_dev - 切换到本地分支 dbscan_dev

git checkout -b dev
一条命令等同于以下两条命令
git branch dev
git checkout dev

strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ git branch dbscan_dev
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ 
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ git branch
  dbscan_dev
* master
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ 
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ git branch -r
  origin/HEAD -> origin/master
  origin/master
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ 
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ git branch -a
  dbscan_dev
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ 
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ git checkout dbscan_dev 
Switched to branch 'dbscan_dev'
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ 
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ git branch
* dbscan_dev
  master
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

4. git push origin dbscan_dev

git add . - 添加项目中所有文件
git commit -m "20200303" - 添加备注 20200303
git push origin dbscan_dev - 提交代码到指定分支 dbscan_dev

strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ ls
data  examples  libdbscan.so  LICENSE  Makefile  obj  README.md  results  scripts  src
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ 
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ git status
On branch dbscan_dev
nothing to commit, working directory clean
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

modified: README.md

strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ git status
On branch dbscan_dev
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	modified:   README.md

no changes added to commit (use "git add" and/or "git commit -a")
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ 
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ git add .
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ 
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ git commit -m "20200303"
[dbscan_dev 8d99cf5] 20200303
 1 file changed, 1 deletion(-)
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ 
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ git push origin dbscan_dev 
Username for 'https://github.com': chengyq116@163.com
Password for 'https://chengyq116@163.com@github.com': 
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 277 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
remote: 
remote: Create a pull request for 'dbscan_dev' on GitHub by visiting:
remote:      https://github.com/ForeverStrongCheng/dbscan_clustering_algorithm/pull/new/dbscan_dev
remote: 
To https://github.com/ForeverStrongCheng/dbscan_clustering_algorithm
 * [new branch]      dbscan_dev -> dbscan_dev
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

5. git push origin dbscan_dev

strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ git status
On branch dbscan_dev
nothing to commit, working directory clean
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ 
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ git branch
* dbscan_dev
  master
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

modified: README.md

strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ git status
On branch dbscan_dev
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	modified:   README.md

no changes added to commit (use "git add" and/or "git commit -a")
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ 
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ git add .
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ 
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ git commit -m "version 1.2."
[dbscan_dev eb77a4b] version 1.2.
 1 file changed, 1 insertion(+), 1 deletion(-)
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

5.1. fatal: The current branch dbscan_dev has no upstream branch.

strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ git push
warning: push.default is unset; its implicit value has changed in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the traditional behavior, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.

Since Git 2.0, Git defaults to the more conservative 'simple'
behavior, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch.

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

fatal: The current branch dbscan_dev has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin dbscan_dev

strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

5.2. git push origin dbscan_dev

strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ git push origin dbscan_dev 
Username for 'https://github.com': chengyq116@163.com
Password for 'https://chengyq116@163.com@github.com': 
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 284 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To https://github.com/ForeverStrongCheng/dbscan_clustering_algorithm
   8d99cf5..eb77a4b  dbscan_dev -> dbscan_dev
strong@foreverstrong:~/darknet_work/dbscan_clustering_algorithm$ 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

6. Branch: master

在这里插入图片描述

References

[1] Yongqiang Cheng, https://yongqiang.blog.csdn.net/

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/608668
推荐阅读
相关标签
  

闽ICP备14008679号