Git 基本命令之github

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值