第一步:建立git仓库(本地)
cd到你的本地项目根目录下,执行git命令

git init

第二步:将项目的所有文件添加到仓库中

git add .

如果想添加某个特定的文件,只需把.换成特定的文件名即可

第三步:将add的文件commit到仓库

git commit -m "注释语句"

第四步:去github上创建自己的Repository,创建页面如下图所示:

第五步:重点来了,将本地的仓库关联到github上

git remote add origin https://github.com/Interesting6/my_numeral_calculations.git

后面的https链接地址换成你自己的仓库url地址

第六步:上传github之前,要先pull一下,执行如下命令:

git pull origin master

敲回车后,会执行输出类似如下

第七步,也就是最后一步,上传代码到github远程仓库

git push -u origin master

执行完后,如果没有异常,等待执行完就上传成功了,中间可能会让你输入Username和Password,你只要输入github的账号和密码就行了

-----------------------------------------------------------------------------------------------------------------------------------

遇到的问题,有时我只需要上传一个文件,而这个文件在GitHub上还没有目录,在刚刚仓库(本地)的目录下打开git bash:

Mr.Black@DESKTOP-4Q3FM6F MINGW64 /e/Sublime/python/calculate (master)
$ git add ./functionroot/iteration_method.py
# 添加该functionroot目录下的文件iteration_method.py

然后提交一下

Mr.Black@DESKTOP-4Q3FM6F MINGW64 /e/Sublime/python/calculate (master)
$ git commit -m "solving nonlinear function in iteration method"
[master c08aed3] solving nonlinear function in iteration method
1 file changed, 133 insertions(+)
create mode 100644 functionroot/iteration_method.py

然后push就出错了:

Mr.Black@DESKTOP-4Q3FM6F MINGW64 /e/Sublime/python/calculate (master)
$ git push -u origin master
To https://github.com/Interesting6/my_numeral_calculations.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/Interesting6/my_numeral_calculations.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.

试了一下网上说的:

Mr.Black@DESKTOP-4Q3FM6F MINGW64 /e/Sublime/python/calculate (master)
$ git pull --rebase origin master
error: cannot pull with rebase: You have unstaged changes.
error: please commit or stash them.

也没用,然后试了下下面的:

You may want to first merge the remote changes (e.g., 'git pull') before pushing again.

在再次推送之前,您可能需要首先合并远程更改(例如,“git pull”)。

that is:

git pull
# Fix any merge conflicts, if you have a `README.md` locally
git push -u origin master

输入下面就通过vim进入一个文件内,我直接保存退出

Mr.Black@DESKTOP-4Q3FM6F MINGW64 /e/Sublime/python/calculate (master)
$ git pull
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/Interesting6/my_numeral_calculations
8fd4a0c..31dacac master -> origin/master
* [new branch] Interesting6-solve_linear_equations -> origin/Interesting6-solve_linear_equations
Merge made by the 'recursive' strategy.
Interpolation.html => Interpolation/Interpolation.html | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename Interpolation.html => Interpolation/Interpolation.html (100%)

然后再push一下就好了,很迷。。

Mr.Black@DESKTOP-4Q3FM6F MINGW64 /e/Sublime/python/calculate (master)
$ git push -u origin master
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 1.61 KiB | 0 bytes/s, done.
Total 6 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 1 local object.
To https://github.com/Interesting6/my_numeral_calculations.git
31dacac..8447fed master -> master
Branch master set up to track remote branch master from origin.

-------------------------------------------------------------------------------------------

下面是我对文件里面的README.md进行更新:

Mr.Black@DESKTOP-4Q3FM6F MINGW64 /e/Sublime/python/calculate (master)
$ git add README.md Mr.Black@DESKTOP-4Q3FM6F MINGW64 /e/Sublime/python/calculate (master)
$ git commit -m "update readme"
[master 3db337d] update readme
1 file changed, 7 insertions(+), 2 deletions(-) Mr.Black@DESKTOP-4Q3FM6F MINGW64 /e/Sublime/python/calculate (master)
$ git push -u origin master
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 433 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/Interesting6/my_numeral_calculations.git
8447fed..3db337d master -> master
Branch master set up to track remote branch master from origin. Mr.Black@DESKTOP-4Q3FM6F MINGW64 /e/Sublime/python/calculate (master)

就好了。

git 里面遇到的问题的更多相关文章

  1. Git 子模块 - submodule

    有种情况我们经常会遇到:某个工作中的项目需要包含并使用另一个项目. 也许是第三方库,或者你 独立开发的,用于多个父项目的库. 现在问题来了:你想要把它们当做两个独立的项目,同时又想在 一个项目中使用另 ...

  2. Git 在团队中的最佳实践--如何正确使用Git Flow

    我们已经从SVN 切换到Git很多年了,现在几乎所有的项目都在使用Github管理, 本篇文章讲一下为什么使用Git, 以及如何在团队中正确使用. Git的优点 Git的优点很多,但是这里只列出我认为 ...

  3. Git与Repo入门

    版本控制 版本控制是什么已不用在说了,就是记录我们对文件.目录或工程等的修改历史,方便查看更改历史,备份以便恢复以前的版本,多人协作... 一.原始版本控制 最原始的版本控制是纯手工的版本控制:修改文 ...

  4. Git Bash的一些命令和配置

    查看git版本号: git --version 如果是第一次使用Git,你需要设置署名和邮箱: $ git config --global user.name "用户名" $ gi ...

  5. 在Ubuntu 16.10 安装 git 并上传代码至 git.oschina.net

    1. 注册一个账号和创建项目 先在git.oschina.net上注册一个账号和新建一个project ,如project name 是"myTest". 2.安装git sudo ...

  6. 史上最详细git教程

    题外话 虽然这个标题很惊悚,不过还是把你骗进来了,哈哈-各位看官不要着急,耐心往下看 Git是什么 Git是目前世界上最先进的分布式版本控制系统. SVN与Git的最主要的区别 SVN是集中式版本控制 ...

  7. [版本控制之道] Git 常用的命令总结(欢迎收藏备用)

    坚持每天学习,坚持每天复习,技术永远学不完,自己永远要前进 总结日常开发生产中常用的Git版本控制命令 ------------------------------main-------------- ...

  8. 【解决方案】Myeclipse 10 安装 GIT 插件 集成 步骤 图解

    工程开发中,往往要使用到集成GIT ,那么下面说说插件安装步骤 PS:以Myeclipse 10 为例,讲解集成安装步骤. ----------------------main------------ ...

  9. git 命令

    切换仓库地址: git remote set-url origin xxx.git切换分支:git checkout name撤销修改:git checkout -- file删除文件:git rm  ...

  10. git亲测命令

    一.Git新建本地分支与远程分支关联问题 git checkout -b branch_name origin/branch_name 或者 git branch --set-upstream bra ...

随机推荐

  1. linux 终端操作快捷键

    熟练使用快捷键可以很大的提高效率,以下列出一些常用的快捷键命令方便随时查阅 1. 移动光标 Ctrl + a 标移到行首.它在多数文本编辑器和 Mozilla 的 URL 字段内可以使用.Ctrl + ...

  2. <2013 07 29> 游泳

    7月12日,在巴塞罗那的海滩学会用狗刨式游泳. 7月14日,在尼斯-戛纳海滩继续练习,稍式蛙泳仰泳. 7月28日,在慕尼黑某湖边吃烧烤,下湖练习. 7月29日,在慕尼黑奥林匹克游泳馆学会了仰泳,稍试自 ...

  3. a标签里面包含img标签,出现a标签的高度高于img标签好几个px

    问题:a标签里面包含img标签,出现a标签的高度高于img标签好几个px 解决: a元素下有一个匿名文本,这个文本外有一个匿名行级盒子,它有的默认vertical-align是baseline的,而且 ...

  4. 解决Raize日历控件显示的问题

    解决Raize日历控件显示的问题 近自己的程序被测试人员发现一个小问题,就是程序中的日历选择框,显示中的“星期一.星期二....”都显示成了“星.....”,我自己看了代码,原来是raize的控件问题 ...

  5. ApexSQL Log 从意外UPDATE和DELETE操作中恢复SQL Server数据

    下载地址:https://www.apexsql.com/download.aspx 如何从意外UPDATE和DELETE操作中恢复SQL Server数据 ApexSQL Log 从意外UPDATE ...

  6. windows 安装 python _ flask

    1:首先安装python虚拟环境;(略) 2: 添加一个虚拟环境: 在你的项目目录里直接 virtualenv venv 启动虚拟环境;\venv\Scripts 直接运行activate 3: 在虚 ...

  7. Django CSRF 原理分析

    原文链接: https://blog.csdn.net/u011715678/article/details/48752873 参考链接:https://blog.csdn.net/clark_fit ...

  8. CentOS 6.4下OpenSSH升级到6.7操作

    一.升级前准备 1.下载openssh-6.7p1.tar.gz: cd /usr/local/src/wget http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/ ...

  9. PHP实现生成唯一编号(36进制的不重复编号)

    当我们要将一个庞大的数据进行编号时,而编号有位数限制,比如5位的车牌号.10位的某证件号码.订单流水号.短网址等等,我们可以使用36进制计算出符合位数的不重复的编号. 我们将0-Z(012345678 ...

  10. ES6 随记(3.1)-- 字符串的拓展

    上一章请见: 1. ES6 随记(1)-- let 与 const 2. ES6 随记(2)-- 解构赋值 4. 拓展 a. 字符串的拓展 有些字符需要 4 个字节储存,比如 \uD83D\uDE80 ...