1、推送到github仓库:
(1)新建并提交和推送
//新建项目
echo "# dbhost" >> README.md
//初始化仓库
git init
git add README.md
git commit -m "first commit"
//切换到主分支:
git branch -M master
//将远程仓库命名为origin:
git remote add origin {远程仓库地址}
//推送
git push -u origin {分支名}
(2)将本地仓库推送
//将远程仓库命名为origin:
git remote add origin {远程仓库地址} 如https://github.com/jimmy/dbhost.git
//切换到主分支:
git branch -M master
//推送
git push -u origin {分支名} 如https://github.com/jimmy/dbhost.git
示例
admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git push -u origin master
info: please complete authentication in your browser...
Enumerating objects: 10, done.
Counting objects: 100% (10/10), done.
Delta compression using up to 16 threads
Compressing objects: 100% (7/7), done.
Writing objects: 100% (10/10), 20.63 KiB | 5.16 MiB/s, done.
Total 10 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/jimmyn/dbhost.git
* [new branch] master -> master
branch 'master' set up to track 'origin/master'.
admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git branch development
admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git push -u origin development
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote:
remote: Create a pull request for 'development' on GitHub by visiting:
remote: https://github.com/jimmy/dbhost/pull/new/de
velopment
remote:
To https://github.com/jimmy/dbhost.git
* [new branch] development -> development
branch 'development' set up to track 'origin/development'.
2、拉取远程仓库代码:
//克隆远程仓库代码
git clone {远程仓库地址} 如https://github.com/jimmy/dbhost.git
//切换分支
git checkout {分支名} 如development
示例
//网络情况不太好会出现超时
admin@jimmy MINGW64 /e/Desktop/1
$ git clone https://github.com/jimmy/dbhost.git
Cloning into 'dbhost'...
fatal: unable to access 'https://github.com/jimmy/dbhost
.git/': Failed to connect to github.com port 443 after 21056 ms: Couldn't connect to server
//使用vpn,或者多尝试几次
admin@jimmy /e/Desktop/1
$ git clone https://github.com/jimmy/dbhost.git
Cloning into 'dbhost'...
remote: Enumerating objects: 10, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 10 (delta 0), reused 10 (delta 0), pack-reused 0
Receiving objects: 100% (10/10), 20.63 KiB | 215.00 KiB/s, done.
//切换目录
admin@jimmy MINGW64 /e/Desktop/1
$ cd dbhost
//查看分支
admin@jimmy MINGW64 /e/Desktop/1/dbhost (master)
$ git branch
* master