1、使用cd命令切换到项目目录,通过git init把它变成Git仓库,再通过git add .把项目添加到仓库;
2、再通过git commit -m "注释内容"把项目提交到仓库";
3、在Github上设置好SSH密钥后,新建一个远程仓库,通过git remote add origin https://github.com/guyibang/TEST2.git将本地仓库和远程仓库进行关联(这里为你的git项目的地址);
4、最后通过git push -u origin master把本地仓库的项目推送到远程仓库(也就是Github)上;
由于新建的远程仓库是空的,所以要加上-u这个参数
5、此时执行第5点命令可能会报如下错误:
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/shut-up/redisDemo.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 pull使远程仓库与本地仓库合并
7、此时git pull也会出现如下错误,
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
因为本地仓库没有与远程仓库进行关联,需要执行命令git branch --set-upstream-to=origin/master master
8、此时再执行git pull命令,再执行git push -u origin master就可以上传成功了。
网友评论