1.1、注册一个GitHub账号
1.2、配置公私钥
https://help.github.com/en/articles/connecting-to-github-with-ssh
1.3、在GitHub上创建个人仓库
1.4、把本地仓库同步到GitHub
# 查看远端
k@k-PC MINGW64 /user/dy201/101-GitRunner/git_learning (temp)
$ git remote -v
zhineng file:///user/dy201/666-backup/zhineng.git (fetch)
zhineng file:///user/dy201/666-backup/zhineng.git (push)
# 远端加一个github仓库
$ git remote add github git@github.com:dy201/git_learning.git
# 本地的push到远端
$ git push github --all
Warning: Permanently added the RSA host key for IP address '52.74.223.119' to the list of known hosts.
Enter passphrase for key '/c/Users/k/.ssh/id_rsa':
Enter passphrase for key '/c/Users/k/.ssh/id_rsa':
Enumerating objects: 30, done.
Counting objects: 100% (30/30), done.
Delta compression using up to 4 threads
Compressing objects: 100% (17/17), done.
Writing objects: 100% (30/30), 2.33 KiB | 53.00 KiB/s, done.
Total 30 (delta 6), reused 0 (delta 0)
remote: Resolving deltas: 100% (6/6), done.
To github.com:dy201/git_learning.git
* [new branch] css-fix -> css-fix
* [new branch] temp -> temp
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com:dy201/git_learning.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
#查看远端和本地的分支
$ git branch -va
css-fix c412e25 Backgroud: orange -> green
master 5cd42df Add the first git command with config
* temp e722d48 second time vim
remotes/github/css-fix c412e25 Backgroud: orange -> green
remotes/github/master 51e2c14 Delete README.md
remotes/github/temp e722d48 second time vim
remotes/zhineng/temp e722d48 second time vim
# 切回到master分支
$ git checkout master
Switched to branch 'master'
# fetch到远端
$ git fetch github master
Enter passphrase for key '/c/Users/k/.ssh/id_rsa':
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (6/6), done.
From github.com:dy201/git_learning
* branch master -> FETCH_HEAD
* [new branch] master -> github/master
# 合并不关联的 fast-forwards
$ git merge --allow-unrelated-histories github/master
Merge made by the 'recursive' strategy.
LICENSE | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
create mode 100644 LICENSE
# 重新push
$ git push github master
Enter passphrase for key '/c/Users/k/.ssh/id_rsa':
Enumerating objects: 18, done.
Counting objects: 100% (18/18), done.
Delta compression using up to 4 threads
Compressing objects: 100% (8/8), done.
Writing objects: 100% (17/17), 1.40 KiB | 42.00 KiB/s, done.
Total 17 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), done.
To github.com:dy201/git_learning.git
51e2c14..65ac276 master -> master