将本地仓库同步到Git远程仓库中

1. 首先在本地创建ssh key

$ ssh-keygen -t rsa -C "your@mail.com"

your@mail.com是在github上注册的邮箱,之后会要求确认路径和输入密码,可以使用默认的一路回车。成功的话会在~/下生成.ssh文件夹,进去,打开id_rsa.pub,复制里面的key。

1240
回到github账户上,进入 Account Settings(账户配置),左边选择SSH ,title随便填,粘贴在你电脑上生成的key
1240

1240

2. 基本信息设置

1. 设置用户名

$ git config --global user.name "Your Name"

2. 设置用户名邮箱

$ git config --global user.email "email@163.com"

3、查看信息

$  git config --list

1240
注:git 解决fatal: Not a git repository

$ git init

注:该设置在github仓库主页显示谁提交了该文件

3. Git克隆操作

将想要修改的远程仓库(github对应的项目)复制到本地

git clone 仓库地址

1240

注:克隆后要cd到克隆的仓库中($ cd 仓库名),否则 git push时会报错

1240

4. 直接在克隆的本地仓库中修改文件

5. 修改文件提交

$ git add 文件名

1240

$ git commit -m ‘对修改文件描述’

1240
最后从本地上传到github

$ git push

1240

注:Git push 有时会报如下错误

The requested URL returned error:403 Forbidden while accessing

解决方法:

在/.git文件夹中找到config文件,记事本打开,进行如下修改:

[remote "origin"]
    url = https://github.com/用户名/仓库名.git
修改为:
[remote "origin"]
    url = https://用户名:密码@github.com/用户名/仓库名.git

Git bash终端中文输出显示乱码问题

注:Git push 报错:

! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/xxxx/xxxx.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 push。具体如下:

1 远程与本地文件同步,自动合并
$ git pull origin master

或者

$ git pull --rebase origin master

--rebase的作用是取消掉本地库中刚刚的commit,并把他们接到更新后的版本库之中。

2 再上传
$ git push -u origin master

或者

$ git push

转载于:https://www.cnblogs.com/ly2012/p/11315600.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值