git提交本地项目到github

本文介绍如何在Windows平台上安装和使用Git进行版本控制。包括初始化仓库、添加文件、提交更改及与远程仓库同步等内容。特别针对解决推送错误和配置远程分支等问题提供详细步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

git学习笔记(windows平台)

   安装git     在需要将项目提交到git的根目录下打开git bush    1 git init 初始化一个git仓库   //将本地文件添加master,先add一个文件    2 git add 一个文件 或者  git add . 提交当前目录中所有的文件    3 git commit -m  "" //链接远程仓库    4 git remote add "远程仓库的地址别名默认是origin" git@git.oschina.net:fuxiaohui/git项目名   在需要将项目提交到git的根目录下打开git bush    5 git remote -v  如果出现以下错误 一,To https://git.oschina.net/fuxiaohui/itone-core.git   ! [rejected]        master -> master (fetch first) error: failed to push some refs to 'https://git.oschina.net/fuxiaohui/itone-core.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.   ! [rejected]        master -> master (fetch first) error: failed to push some refs to 'https://git.oschina.net/fuxiaohui/itone-core.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 查看远程分支命令 git branch -a 执行  git branch --set-upstream-to=origin/远程分支的名字 本地分支的名字  二,如果push出现错误说明本地仓库与远程仓库不一致,得吧远程仓库的值fetch到本地来   7 git fetch   8 git merge   9 $ git fetch   10 $ git merge   这2句命令等价于   $ git pull      可是,这时候又出现了如下的问题:     1上面出现的 [branch "master"]是需要明确(.git/config)如下的内容     [branch "master"]     remote = origin     merge = refs/heads/master   这等于告诉git2件事:      1,当你处于master branch, 默认的remote就是origin。      2,当你在master branch上使用git pull时,没有指定remote和branch,那么git就会采用默认的remote(也就是       origin)来merge在master branch上所有的改变   如果不想或者不会编辑config文件的话,可以在bush上输入如下命令行:   $ git config branch.master.remote origin    $ git config branch.master.merge refs/heads/master    之后再重新git pull下。最后git push你的代码吧。   

   6 git push -u "远程仓库地址别名" master

判断公钥是否添加成功 ssh -T git@git.oschina.net
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值