Chinaunix首页 | 论坛 | 博客
  • 博客访问: 955396
  • 博文数量: 116
  • 博客积分: 3923
  • 博客等级: 中校
  • 技术积分: 1337
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-23 01:22
文章分类

全部博文(116)

文章存档

2013年(1)

2012年(17)

2011年(69)

2009年(29)

分类: LINUX

2012-01-18 00:55:58

今天终于把代码搞到github上去,主要是首先开个github的帐号,然后创建一个仓库,创建好以后,就直接点击仓库名称,就会有提示,教你如何去一步一步安装,提示如下:

==========================================================================================
Global setup:

 Set up git
  git config --global user.name "vincent"
  git config --global user.email vincent.cws2008@gmail.com
     

Next steps:

  mkdir vincent_code
  cd vincent_code
  git init
  touch README
  git add README
  git commit -m 'first commit'
  git remote add origin git@github.com:chenws/vincent_code.git
  git push -u origin master
     

Existing Git Repo?

  cd existing_git_repo
  git remote add origin git@github.com:chenws/vincent_code.git
  git push -u origin master
     

Importing a Subversion Repo?

  Click here
     

When you're done:

  Continue

==========================================================================================

按照提示去做,就基本没什么大问题,不过在第一步globle setup中,需要产生一对RSA的key,然后把公钥复制到github上去,如下所示:


==========================================================================================
  1. Check for SSH keys. Have an existing key pair? You can skip to Step 4.

    First, we need to check for existing ssh keys on your computer:

    $ cd ~/.ssh

    If it says “No such file or directory“ skip to step 3. Otherwise continue to step 2.

  2. Backup and remove existing SSH keys.

    Since there is already an SSH directory you’ll want to back the old one up and remove it:

    $ ls $ mkdir key_backup $ cp id_rsa* key_backup $ rm id_rsa*
  3. Generate a new SSH key.

    To generate a new SSH key, enter the code below. We want the default settings so when asked to enter a file in which to save the key, just press enter.

    $ ssh-keygen -t rsa -C "your_email@youremail.com"

    Now you need to enter a passphrase.

    Why do passphrases matter?

    Which should give you something like this:

  4. Add your SSH key to GitHub.

    On the GitHub site Click “Account Settings” > Click “SSH Public Keys” > Click “Add another public key”

    Open the id_rsa.pub file with a text editor (Notepad, TextEdit, or gedit will do just fine). This is your public SSH key. You may need turn on “view hidden files” to find it because the .ssh directory is hidden. It’s important you copy your SSH key exactly as it is written without adding any newlines or whitespace. Now paste it into the “Key” field.

    Can’t view hidden files? Other ways to copy:

    Now paste it into the “Key” field.

    Paste your SSH Key

    Hit “Add Key.”

  5. Test everything out.

    To make sure everything is working you’ll now SSH to GitHub. Don’t change the “git@github.com” part. That’s supposed to be there.

    $ ssh -T git@github.com

    Which should give you this:

    Don’t worry, this is supposed to happen. Type “yes”.

    Having problems?

==========================================================================================

如果中间有提示你的id_rsa私钥too open表示你必须修改id_rsa的属性,chmod 600 ~/.ssh/id_rsa,
如果没有就不用修改,然后你运行Git push时提示“fatal: The remote end hung up unexpectedly”,
在网上找了一下,结果需要把下面代码加入到.bashrc中:


  1. SSH_ENV="$HOME/.ssh/environment"

  2. # start the ssh-agent
  3. function start_agent {
  4.     echo "Initializing new SSH agent..."
  5.     # spawn ssh-agent
  6.     ssh-agent | sed 's/^echo/#echo/' > "$SSH_ENV"
  7.     echo succeeded
  8.     chmod 600 "$SSH_ENV"
  9.     . "$SSH_ENV" > /dev/null
  10.     ssh-add
  11. }

  12. # test for identities
  13. function test_identities {
  14.     # test whether standard identities have been added to the agent already
  15.     ssh-add -l | grep "The agent has no identities" > /dev/null
  16.     if [ $? -eq 0 ]; then
  17.         ssh-add
  18.         # $SSH_AUTH_SOCK broken so we start a new proper agent
  19.         if [ $? -eq 2 ];then
  20.             start_agent
  21.         fi
  22.     fi
  23. }

  24. # check for running ssh-agent with proper $SSH_AGENT_PID
  25. if [ -n "$SSH_AGENT_PID" ]; then
  26.     ps -ef | grep "$SSH_AGENT_PID" | grep ssh-agent > /dev/null
  27.     if [ $? -eq 0 ]; then
  28.     test_identities
  29.     fi
  30. # if $SSH_AGENT_PID is not properly set, we might be able to load one from
  31. # $SSH_ENV
  32. else
  33.     if [ -f "$SSH_ENV" ]; then
  34.     . "$SSH_ENV" > /dev/null
  35.     fi
  36.     ps -ef | grep "$SSH_AGENT_PID" | grep -v grep | grep ssh-agent > /dev/null
  37.     if [ $? -eq 0 ]; then
  38.         test_identities
  39.     else
  40.         start_agent
  41.     fi
  42. fi

加完之后,需要再执行一步:

ssh-add /home/vincent/.ssh/id_rsa

把私钥加到代理中,现在就可以在ubuntu下把README文件push到github服务器,接下来我就要把剩下的很多文件也搞上去,首先,看能不能删除文件:

  1. echo “test MM” > MM
  2. git add MM
  3. git commit –m ‘add MM’
  4. git push

  5. git rm MM
  6. git –m ‘test rm MM’
  7. git commit –m ‘test rm MM’
  8. git push

发现没问题,然后我解压windows目录下的原文件放到ubuntu个仓库目录下,再执行:

git add –v .

git commit –m ‘add codes’

提交到本地仓库的时候,发现有很多trailing whitespace的错误和indent SP followed by a TAB错误,在网上找了一下说是因为不同文件系统引起的,主要是后面文件后有空格或者TAB键之类,我就直接在/home/Vincent/test_github/codes仓库目录下的.git/hooks/pre-commit中的:

bad_line("trailing whitespace", $_);

bad_line("indent SP followed by a TAB", $_);

两行都屏蔽,然后再执行

git commit –m ‘add codes’ 

git push

然后提交成功,再在github上看到已经提交的所有文件。

再下次提交时,需要先同步git服务器的数据,更新到本地:

git pull git@github.com:xxx/codes.git master

更新服务器上的信息到本地,如果有冲突会自己自动的把服务器的信息覆盖本地的,小心!

阅读(7311) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~