git 为当前文件夹添加远程仓库
AzerothSong 发布于 阅读:304 git
使用场景:
我本地创建了一个项目,需要推送到远程仓库
1、在当前文件夹初始化git仓库
git init
2、添加远程仓库(以gitee为例,GitHub同理的就是后面的url做一下替换。
我已经把本地的id_rsa.pub
配置在了gitee上面,所以直接使用了ssh,没有配置的同学可以参考文章git生成ssh,使用ssh拉取推送代码
git remote add origin git@gitee.com:username/project.git
3、拉取远程仓库信息
git pull origin master --allow-unrelated-histories
假如出现了如下问题,请执行git config pull.rebase false
(默认策略)
hint: You have divergent branches and need to specify how to reconcile them.
hint: You can do so by running one of the following commands sometime before
hint: your next pull:
hint:
hint: git config pull.rebase false # merge (the default strategy)
hint: git config pull.rebase true # rebase
hint: git config pull.ff only # fast-forward only
hint:
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
fatal: Need to specify how to reconcile divergent branches.
4、最后将代码添加到本地仓库然后上传到远程仓库就可以了
git add .
git commit -m "object init"
git push -u origin master