使用git提交代码到github
2017-09-05 13:28
344 查看
首次使用git要做的工作:
配置用户信息git config –global user.name “nc”
git config –global user.email “nicahead@gmail.com”
配置SHH
配置shh key是让本地git项目与远程的github建立联系
先检查是否已经有SSH Key,打开Git Bash,输入
cd ~/.ssh
如果没有.ssh这个目录,则生成一个新的SSH,输入
ssh-keygen -t rsa -C "your e-mail"
接下来一顿回车,可能中间会输入yes
出现这种类型的图案,则配置成功
添加 SSH Key 到 GitHub
打开Git Bash,然后输入
cd ~/.ssh
进入到.shh文件夹中再输入ls,查看是否有id_rsa.pub文件
输入cat命令,打开id_rsa.pub文件
cat id_rsa.pub
将该ssh字符串复制下来,进入Github官网,点击+旁边的头像,再按settings进入设置 ,点击New SSH key创建新的 SSH Key
验证配置是否成功
打开Git Bash,然后输入
ssh -T git@github.com, 显示success信息
一次完整的本地代码上传到github的操作:
github上新建一个仓库 new repository在本地项目的文件夹下执行
git init命令 ,初始化版本库
执行
git add 文件名,添加文件到版本库,可以执行
git add .将文件夹下的所有文件添到版本库
执行
git commit -m “标示”,创建这次版本的标示
出现提示:
On branch master nothing to commit, working directory clean
解决方法:
rm -rf .git/然后从第二步开始重新操作
和仓库建立连接
git remote add origin git@github.com:yourName/yourname.github.io.git
出现提示:
fatal: remote origin already exists.
解决方法:
git remote rm origin
开始上传
git push -u origin master
出现提示:
fatal: unable to access 'https://github.com/yourname/yourname.github.io.git/': The requested URL returned error: 403
解决方法: 通过ssh的方式与仓库建立连接
git remote rm origin
出现提示:
$ git push -u origin master To git@github.com:nicahead/nicahead.github.io.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'git@github.com:nicahead/nicahead.github.io.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 pull --rebase origin master 然后 git push -u origin master
相关文章推荐
- Android Studio如何使用Git提交代码到GitHub和OsChina并解决冲突
- 使用Git向Github提交代码
- Ubuntu下使用git提交代码至GitHub
- 使用Git往github上提交代码时出现[packet_write_wait connection to xx.xx.xx.xx Broken pipe]错误的解决办法:
- Android Studio如何使用Git提交代码到GitHub和OsChina并解决冲突
- 如何使用git命令同步代码到github或提交到多个远程仓库
- 使用git提交本地代码到github上
- 使用GIT命令行提交代码到GitHub
- 如何使用git工具向github提交代码
- 如何使用git工具向github提交代码
- 使用git提交代码到github
- Ubuntu下使用git提交代码至GitHub
- ubuntu16系统中pycharm下使用git将代码提交到github仓库
- Android Studio如何使用Git提交代码到GitHub和OsChina并解决冲突
- swift详解之二十--------在xcode中使用git管理源代码,将代码提交到github
- Ubuntu下使用git提交代码至GitHub
- 使用git命令行提交代码到github上报错(一)
- eclipse中使用git提交代码到github
- Git的基本了解与使用、向github提交代码
- Android Studio如何使用Git提交代码到GitHub和OsChina并解决冲突