git将本地代码 和服务器git@osc 上的代码 关联

将本地代码 和服务器git@osc 上的代码 关联

要使用git 首先,你得安装一个git

下载  http://git-scm.com/downloads

安装完成后,需要简单的配置一下,打开 Git Bash

填写用户名和邮箱,会出现在提交记录中,尽量和 git@osc 中保持一致

git config --global user.name "你的名字"
git config --global user.email "你的Email"

进入一个本地文件夹,作为待提交目录,初始化

初始化
git init

把该目录下的所有文件全部提交到缓冲区
git add .

第一次提交
git commit -m "first commit"

此时将代码提交到了本地 master 下,还没有提交到服务器

添加远程库

移除远程仓库地址
git remove rm origin

添加新的地址
git remote add origin https://git.oschina.net/panie/blog.git

查询当前设置的远程库
git remote -v

拉取和提交服务器上的代码

拉取服务器上的代码
git pull origin master

git pull origin master --allow-unrelated-histories


提交本地到服务器

git push origin master

https 方式每次都要输入密码,按照如下设置即可输入一次就不用再手动输入密码

设置记住密码(默认15分钟)
git config --global credential.helper cache

自定义时间(一个小时)
git config credential.helper 'cache --timeout=3600'

长期存储密码
git config --global credential.helper store

生成ssh 秘钥

ssh-keygen -t rsa -C "kenie123@163.com"

原文地址:https://www.cnblogs.com/panie2015/p/6150513.html