github 学习

终于有动力用github了,各种公司都要有自己的github主页。今天终于也成功上传了自己的小小项目,记录一下:

  • 在自己的github 中create a new repository, 装一个git bash 的客户端
  • 在本地创建ssh key : $ ssh-keygen -t rsa -C "your_email@youremail.com", 后面要求确认路径和输入密码,默认回车就好, 找.ssh 文件夹下 id_rsa.pub , 复制到github 中的settings 中的ssh keys,  title 随便, key 黏贴

  • 验证是否成功:  git bash 中输入 $ ssh -T git@github.com, yes 之后,出现 you're successfully authenticated, but github does not provide shell access....成功喽
  • 接下来就是将本地仓库上传到github上。 设置username 和 email

 $ git config --global user.name "your name"
$ git config --global user.email "   "

  • 进入上传的仓库(要上传的地址), 添加远程地址:

 $ git remote add origin git@github.com:yourName/yourRepo.git

yourname 和 yourrepo 是你的用户名和新建的仓库

  • 提交

            $ git add yourfile    (yourfile 是你要上传的文件)   // git add 添加要commit 的文件

            $ git commit -m "first commit"             // git commit 提交

  • 上传代码喽

              $ git push origin master  // git push 就是将本地仓库推送到远程服务器上 

              $ git pull 命令相反

          可以使用  git status 查看文件的差别

gitignore 文件 就git 需要忽略的文件,代码的编译,调用会产生很多中间文件和可执行文件,不是代码不需要github 管理。git  add -A 会添加所有的文件,git add 要一个一个的加。 需要.gitignore , 

.gitignore是这样写的:bin和obj是编译目录,里面都不是源代码,忽略;suo文件是vs2010的配置文件,不需要。这样你在git status的时候就只会看到源代码文件了,就可以放心的git add -A了。

bin
.suo
obj

  

怎么搞一个分支修改自己的工程呢??

新建的代码库仅有一个自动建立的主分支(master),可以新建分支用于开发:

git branch develop master     // 新建一个develop 的分支,基于master 的分支

git checkout develop     // 切换到develop 分支,

  

再push 新分支。
git push -u origin

  如果是新建分支第一次push,会提示:
  fatal: The current branch develop has no upstream branch.
  To push the current branch and set the remote as upstream, use
  git push --set-upstream origin develop
  输入这行命令,然后输入用户名和密码,就push成功了。

  以后的push就只需要输入git push origin

  

原文地址:https://www.cnblogs.com/fanhaha/p/7595904.html