首先在github上新建一个仓库:
gitrepositytest
创建之后进入新建的仓库,下面有提示的命令行操作
echo "# gitrepositytest" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/matengbing/gitrepositytest.git
git push -u origin master
按照提示的代码操作
matengbing@LAPTOP-AGEC3S6U MINGW64 /d/github (master)
$ mkdir gitrepositytest
matengbing@LAPTOP-AGEC3S6U MINGW64 /d/github (master)
$ cd gitrepositytest/
matengbing@LAPTOP-AGEC3S6U MINGW64 /d/github/gitrepositytest (master)
$ echo "# gitrepositytest" >> README.md
matengbing@LAPTOP-AGEC3S6U MINGW64 /d/github/gitrepositytest (master)
$ git init
Initialized empty Git repository in D:/github/gitrepositytest/.git/
matengbing@LAPTOP-AGEC3S6U MINGW64 /d/github/gitrepositytest (master)
$ git add README.md
warning: LF will be replaced by CRLF in README.md.
The file will have its original line endings in your working directory
matengbing@LAPTOP-AGEC3S6U MINGW64 /d/github/gitrepositytest (master)
$ git commit -m "first commit"
[master (root-commit) bb26e9f] first commit
1 file changed, 1 insertion(+)
create mode 100644 README.md
matengbing@LAPTOP-AGEC3S6U MINGW64 /d/github/gitrepositytest (master)
$
matengbing@LAPTOP-AGEC3S6U MINGW64 /d/github/gitrepositytest (master)
$
matengbing@LAPTOP-AGEC3S6U MINGW64 /d/github/gitrepositytest (master)
$ git remote add origin https://github.com/matengbing/gitrepositytest.git
matengbing@LAPTOP-AGEC3S6U MINGW64 /d/github/gitrepositytest (master)
$ git push -u origin master
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 228 bytes | 228.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote:
remote: Create a pull request for 'master' on GitHub by visiting:
remote: https://github.com/matengbing/gitrepositytest/pull/new/master
remote:
To https://github.com/matengbing/gitrepositytest.git
* [new branch] master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
matengbing@LAPTOP-AGEC3S6U MINGW64 /d/github/gitrepositytest (master)
$
如果github没有新建仓库,直接在命令行操作push会报错
matengbing@LAPTOP-AGEC3S6U MINGW64 /d/github/gitrepositytest (master)
$ git remote add origin https://github.com/matengbing/gitrepositytest.git
matengbing@LAPTOP-AGEC3S6U MINGW64 /d/github/gitrepositytest (master)
$ git push -u origin master
remote: Repository not found.
fatal: repository 'https://github.com/matengbing/gitrepositytest.git/' not found
上传成功后在github仓库界面查看
接着,我们在命令行创建一个分支feature-develop并切换分支
matengbing@LAPTOP-AGEC3S6U MINGW64 /d/github/gitrepositytest (master)
$ git checkout -b feature-develop
Switched to a new branch 'feature-develop'
matengbing@LAPTOP-AGEC3S6U MINGW64 /d/github/gitrepositytest (feature-develop)
$ git branch
* feature-develop
master
新建一个文件,add,commit之后push到远程分支(没有建立新分支,直接push会自动创建分支)
matengbing@LAPTOP-AGEC3S6U MINGW64 /d/github/gitrepositytest (feature-develop)
$ touch test.txt
matengbing@LAPTOP-AGEC3S6U MINGW64 /d/github/gitrepositytest (feature-develop)
$ git add test.txt
matengbing@LAPTOP-AGEC3S6U MINGW64 /d/github/gitrepositytest (feature-develop)
$ git status
On branch feature-develop
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: test.txt
matengbing@LAPTOP-AGEC3S6U MINGW64 /d/github/gitrepositytest (feature-develop)
$ git commit -m "test.txt"
[feature-develop 7f24aea] test.txt
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 test.txt
matengbing@LAPTOP-AGEC3S6U MINGW64 /d/github/gitrepositytest (feature-develop)
$ git push origin feature-develop
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 271 bytes | 271.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote:
remote: Create a pull request for 'feature-develop' on GitHub by visiting:
remote: https://github.com/matengbing/gitrepositytest/pull/new/feature-develop
remote:
To https://github.com/matengbing/gitrepositytest.git
* [new branch] feature-develop -> feature-develop
matengbing@LAPTOP-AGEC3S6U MINGW64 /d/github/gitrepositytest (feature-develop)
$
在github仓库界面查看新分支
已经建立了新的分支,代码也已经上传到新分支
查看所有分支信息
$ git branch -av
* feature-develop 7f24aea test.txt
master bb26e9f first commit
remotes/origin/feature-develop 7f24aea test.txt
remotes/origin/master bb26e9f first commit
matengbing@LAPTOP-AGEC3S6U MINGW64 /d/github/gitrepositytest (feature-develop)
$
版权声明:本文为matengbing原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。