Github本地新建分支并推送远程仓库

有时候需要在本地新建了代码分支,想直接推送到远程仓库并新建代码分支,操作如下:

第一步,先初始化本地git仓库(如果是从远程仓库拉下来的可以忽略这一步)

damon@damon-Latitude-7380:Ntrip$ git init
Initialized empty Git repository in /home/damon/Work/ntrip/Ntrip/.git/

第二步,添加远程仓库:

damon@damon-Latitude-7380:Ntrip$ git remote add origin https://github.com/lxxxen/ntrip
damon@damon-Latitude-7380:Ntrip$ git remote -v
origin	https://github.com/lxxxen/ntrip (fetch)
origin	https://github.com/lxxxen/ntrip (push)

第三步,把本地的代码先commit:

damon@damon-Latitude-7380:Ntrip$ git status
On branch master

Initial commit

Untracked files:
  (use "git add ..." to include in what will be committed)

	makefile
	ntripclient
	ntripclient.c
	serial.c
	startntripclient.sh

nothing added to commit but untracked files present (use "git add" to track)
damon@damon-Latitude-7380:Ntrip$ git add .
damon@damon-Latitude-7380:Ntrip$ git status
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached ..." to unstage)

	new file:   makefile
	new file:   ntripclient
	new file:   ntripclient.c
	new file:   serial.c
	new file:   startntripclient.sh

damon@damon-Latitude-7380:Ntrip$ git commit -m "NEW: new branch for ntrip serila."
[master (root-commit) ee026c3] NEW: new branch for ntrip serila.
 5 files changed, 1486 insertions(+)
 create mode 100755 makefile
 create mode 100755 ntripclient
 create mode 100755 ntripclient.c
 create mode 100644 serial.c
 create mode 100755 startntripclient.sh

第四步,新建本地分支并推送远程仓库:

damon@damon-Latitude-7380:Ntrip$ git branch
* master
damon@damon-Latitude-7380:Ntrip$ 
damon@damon-Latitude-7380:Ntrip$ 
damon@damon-Latitude-7380:Ntrip$ git branch test
damon@damon-Latitude-7380:Ntrip$ 
damon@damon-Latitude-7380:Ntrip$ git push origin test
Username for 'https://github.com': [email protected]
Password for 'https://[email protected]@github.com': 
Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (7/7), 25.23 KiB | 0 bytes/s, done.
Total 7 (delta 0), reused 0 (delta 0)
remote: 
remote: Create a pull request for 'test' on GitHub by visiting:
remote:      https://github.com/lxxxxx/ntrip/pull/new/test
remote: 
To https://github.com/lxxxxx/ntrip
 * [new branch]      test -> test

完事!

你可能感兴趣的:(git)