主要过程详解如下:
https://www.cnblogs.com/ldq2016/p/5468987.html
对于更新主要流程是:
- 关联远程
$ git remote add origin git@github.com:susanhc/programming.git
- susanhc是账号名称
- programming是你所建的仓库
上述语句将二者进行关联
这可以解决错误:
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
但是有可能在关联远程或push出现如下错误:
fatal: Not a git repository (or any of the parent directories): .git
解决:在命令行输入 git init 然后回车就好了
- 长传本地文件
$ git add .
- 跟踪任何的文件改动
$ git commit -m "34"
添加注释,引号中是你的解释内容
$ git push origin master
把本地文件上传到github仓库中去
- git push 时报错 error:failed to push some refs to ‘git@xxxxxx’
原因:这是一个新建的一个仓库,提交到github时,没有 pull下来,导致 github中的README.md文件不在本地代码目录中
$ git push -u origin master
To github.com:Houttuyniae/notes.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:Houttuyniae/notes.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
需要先执行 git pull --rebase origin master
把 README.md 下来
如果在你pull之前,又执行了commit,提交了一次,则会报错
$ git pull --rebase origin master
error: cannot pull with rebase: You have unstaged changes.
error: additionally, your index contains uncommitted changes.
error: please commit or stash them.
需要先执行 git stash 缓存一下 最后在 push
$ git push -u origin master
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 590 bytes | 590.00 KiB/s, done.
Total 5 (delta 3), reused 0 (delta 0)
remote: Resolving deltas: 100% (3/3), completed with 3 local objects.
To github.com:Houttuyniae/notes.git
d81c6a9..929dc11 master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.