今天终于把代码搞到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上去,如下所示:
==========================================================================================
- 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.
- 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*
- 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:
- 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.
Hit “Add Key.”
- 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中:
- SSH_ENV="$HOME/.ssh/environment"
-
-
# start the ssh-agent
-
function start_agent {
-
echo "Initializing new SSH agent..."
-
# spawn ssh-agent
-
ssh-agent | sed 's/^echo/#echo/' > "$SSH_ENV"
-
echo succeeded
-
chmod 600 "$SSH_ENV"
-
. "$SSH_ENV" > /dev/null
-
ssh-add
-
}
-
-
# test for identities
-
function test_identities {
-
# test whether standard identities have been added to the agent already
-
ssh-add -l | grep "The agent has no identities" > /dev/null
-
if [ $? -eq 0 ]; then
-
ssh-add
-
# $SSH_AUTH_SOCK broken so we start a new proper agent
-
if [ $? -eq 2 ];then
-
start_agent
-
fi
-
fi
-
}
-
-
# check for running ssh-agent with proper $SSH_AGENT_PID
-
if [ -n "$SSH_AGENT_PID" ]; then
-
ps -ef | grep "$SSH_AGENT_PID" | grep ssh-agent > /dev/null
-
if [ $? -eq 0 ]; then
-
test_identities
-
fi
-
# if $SSH_AGENT_PID is not properly set, we might be able to load one from
-
# $SSH_ENV
-
else
-
if [ -f "$SSH_ENV" ]; then
-
. "$SSH_ENV" > /dev/null
-
fi
-
ps -ef | grep "$SSH_AGENT_PID" | grep -v grep | grep ssh-agent > /dev/null
-
if [ $? -eq 0 ]; then
-
test_identities
-
else
-
start_agent
-
fi
-
fi
加完之后,需要再执行一步:
ssh-add /home/vincent/.ssh/id_rsa
把私钥加到代理中,现在就可以在ubuntu下把README文件push到github服务器,接下来我就要把剩下的很多文件也搞上去,首先,看能不能删除文件:
- echo “test MM” > MM
-
git add MM
-
git commit –m ‘add MM’
-
git push
-
-
git rm MM
-
git –m ‘test rm MM’
-
git commit –m ‘test rm MM’
-
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
更新服务器上的信息到本地,如果有冲突会自己自动的把服务器的信息覆盖本地的,小心!
阅读(7328) | 评论(0) | 转发(0) |