github实践

  最近需要使用github来代码管理。github有很多优点,唯一的缺点可能对于一些公司非开源的项目。废话不多说了,开始实践吧。

  首先,安装git,安装完后需要你注册一个github的一个账户。这些简单细节就不多说了。

  注册完github后,你需要穿件你创建你自己的分支:登录你的github,左下角会提示你创建自己的分支"Create a Repository".点击进去按照步骤一点点写,如果选择私有项目,必须要付费,最后完成创建新分支。

  配置你的git环境:在创建完成你的新分支后,会有出现一些code,是教你配置你的git环境和git命令(记住这些命令是你使用github常用到的命令,都在这里了):

Global setup:
 Set up git
  git config --global user.name "Your Name"
  git config --global user.email xxx@gmail.com
      
Next steps:
  mkdir your-project
  cd your-project
  git init
  touch README
  git add README
  git commit -m 'first commit'
  git remote add origin git@github.com:xxxxxx/your-project.git
  git push -u origin master
      
Existing Git Repo?
  cd existing_git_repo
  git remote add origin git@github.com:xxxxxx/your-project.git
  git push -u origin master
      
Importing a Subversion Repo?
  Check out the guide for step by step instructions.
      
When you're done:
  Continue

  在管理代码库之前,你必须要把安装和设置ssh-key:

[~/.ssh]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/tom/.ssh/id_rsa): <enter>
Enter passphrase (empty for no passphrase): <输入key的密碼,或直接按下enter使用空密码>
Enter same passphrase again: <再输入一次密码>
Your identification has been saved in /home/tom/.ssh/id_rsa.
Your public key has been saved in /home/tom/.ssh/id_rsa.pub.
The key fingerprint is:
50:43:77:c6:97:af:61:82:dc:ea:9b:6b:67:d4:1b:61 tom@volcano

将id_rsa.pub的内容粘贴到你github帐号中的SSH Public Keys的位置。注意小心不要复制到空格。

  建立的本地仓储,并push到远程仓储.这里可以是你自己,或者别人。步骤是一样的:对某个分支fork(自己的账户的话就不用fork了,你本来就看得见),得到“git@github.com:xxx/xxx.git”类似的东西。记住每台机器的公钥都必须要添加到你github帐号中的SSH Public Keys的位置。要不然机器对该分支无法进行操作,步骤如下:

a.如本人初始化
mkdir heart-beat
cd heart-beat
git init
touch README
git add README
git commit -m 'first commit'
git remote add origin git@github.com:xiaobing/heart-beat.git
git push -u origin master

b.如第三方修改代码提交
git clone git@github.com:username/Spoon-Knife.git
cd Spoon-Knife
git remote add upstream git://github.com/octocat/Spoon-Knife.git
git fetch upstream
//修改提交你的代码
git status
git add *.java
git commit -m 'information....'
git push origin master

  好了,够简单吧。其实就是这么简单。

  

原文地址:https://www.cnblogs.com/slider/p/2458084.html