添加github仓库到本地到本地项目

1.本地项目文件夹下初始化git项目
git init
2.为本地项目添加别名为 origin 地址为git@github.com:williamvittso/.....的远端仓库

git remote add origin git@github.com:williamvittso/.....

3.推送

git push -u origin master

如果你远端仓库不是空的此处可能会报错需要:

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 pull <remote> <branch>
或者干脆设置成永久的: git branch --set-upstream-to=origin/<branch> master

然后你可能看到本地git拒绝拉取

 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:williamvittso/timestamp.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 --allow-unrelated-histories
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。