安装和配置Git
————————————————————————————–
1. 下载和安装最新版本的Git: http://git-scm.com/downloads

2. 设置用户信息

$ git config  –global user.name Falcon

Administrator@PC-201107130118 ~/mydjango/hello/weather
$ git config –global user.email falcon_chen@qq.com

Administrator@PC-201107130118 ~/mydjango/hello/weather
$ git config –global credential.helper cache

在github中找到 Account Settings—>Account Admin ,找到一下信息:

Your API token is e97279836f0d415a3954c1193dba522f —keep it secret! Changing your password will

generate a new token

$ git config –global github.user falconchen      //github 上的用户名
$ git config –global github.token c98c9e14e24b2735ace34d175cccf115

3. 生成SSH密钥对,使用dsa加密
$ ssh-keygen -t dsa -C “falcon_chen@qq.com”

Generating public/private dsa key pair.
#这里输入密钥文件名和保存位置. 短语
Enter file in which to save the key (/home/Administrator/.ssh/id_dsa): falcon_github
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in falcon_github.
Your public key has been saved in falcon_github.pub.

.. note::

可以使用dotcloud的密钥::

ssh登陆或用sftp打开你的dotcloud远程主机,~/.ssh/authorized_keys2即为公钥,
私钥位于本地用户家目录下的.dotcloud文件夹,带.key 后缀名,密钥使用dsa加密算法。

4. 添加密钥
打开 https://github.com/settings/ssh ,点击Add key 把公钥内容复制粘贴上去即可

5. 验证测试

如果使用dotcloud的密钥对,此时私钥位置需要 ssh -i 指定,默认使用用户目录/.ssh/id_rsa 文件

$ ssh -i .dotcloud/onepythoner.conf.key -T git@github.com
Connection closed by 207.97.227.239

如果出现下面的信息表示连接成功

$ ssh -i .dotcloud/onepythoner.conf.key -T git@github.com
The authenticity of host ‘github.com (207.97.227.239)’ can’t be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘github.com,207.97.227.239’ (RSA) to the list of known hosts.
Hi falconchen! You’ve successfully authenticated, but GitHub does not provide shell access.

参考:https://help.github.com/articles/generating-ssh-keys

为方便操作把 onepythoner.conf.key 移动重命名到~/.ssh/id_dsa ,并把权限设置为600
执行$ssh -T git@github.com ,命令提示如下:
Hi falconchen! You’ve successfully authenticated, but GitHub does not provide shell access.

关于 ssh -i参数的说明::

-i identity_file
Selects a file from which the identity (private key) for public key authentication is read.  The default is ~/.ssh/identity for protocol version 1,
and ~/.ssh/id_dsa, ~/.ssh/id_ecdsa and ~/.ssh/id_rsa for protocol version 2.  Identity files may also be specified on a per-host basis in the con‐
figuration file.  It is possible to have multiple -i options (and multiple identities specified in configuration files).  ssh will also try to load
certificate information from the filename obtained by appending -cert.pub to identity filenames.

创建新项目
————————————————————————————–
参考 https://help.github.com/articles/creating-a-new-repository ,没什么好说的,按步就班即可
或者直接打开https://github.com/new操作

我创建的项目地址:https://github.com/falconchen/FetionWether
https://github.com/falconchen/FetionWether.git
https://github.com/falconchen/git@github.com:falconchen/FetionWether.git

在本地使用Git创建并提交更新:
————————————————————————————–
1.上一步在创建新项目时加入一个Readme.md,同时作为项目的初始化

2.务必在之前已经配置
$ git config –global github.user falconchen      //github 上的用户名
$ git config –global github.token c98c9e14e24b2735ace34d175cccf115

3. Git命令操作::

$ cd mydjango/
$ git init
$ git add .
$ git status
$ git commit -m “git first blood”
$ git remote add origin git@github.com:falconchen/FetionWether.git
$ git push -u origin master

如出现以下错误::

To git@github.com:falconchen/FetionWether.git
! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to ‘git@github.com:falconchen/FetionWether.git’
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. ‘git pull’) before pushing again.  See the
‘Note about fast-forwards’ section of ‘git push –help’ for details.

则需要执行::

$ git fetch origin
$ git merge origin/master
$ git push -u origin master

clone (可写)

$ git clone git@github.com:falconchen/FetionWether.git
对部分文件修改后…
$ git commit -a -m “some modify”
$ git push

在dotcloud 工作目录 执行git pull 拉取数据

(env)dotcloud@hello-default-www-0:~/code$ git pull
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (1/1), done.
remote: Total 3 (delta 1), reused 3 (delta 1)
Unpacking objects: 100% (3/3), done.
From github.com:falconchen/FetionWether
6105b42..1452ac7  master     -> origin/master
Updating 6105b42..1452ac7
Fast-forward
requirements.txt |    2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

添加标签

$ git tag -a v1.0.0 -m ‘version 1.0.0.0’
修改文件并commit 后

显示特定标签
$git tag
$ git show v1.0 -lw

使用这个命令可以在本地找到未合并的分支
git branch –no-merged

在dotcloud直接使用git 进行源码更新
1. 添加一个dotcloud的镜像库
地址名为ssh://dotcloud@uploader.dotcloud.com:443/项目名,这个地址不能用git clone检出源码 ,也不支持git pull 的拉取。也就是说只能用来提交而不能检出了。于是想把dotcloud当私人专用git服务器的计划就泡汤了。想到的方法,以后如果不在本地开发,可以从github检出代码,更改代码后再push到dotcloud上,这样就不用ssh到dotcloud执行git push了,( 但重启服务器或者执行脚本还是必须SSH, 但实际而言还是SSH登陆方便,),步骤如下

$ git remote add dotcloud ssh://dotcloud@uploader.dotcloud.com:443/hello
可以看到此时有两个远程库了
$ git remote
dotcloud
origin

2.执行推送(强行push所有branch)
$ git push -f –all dotcloud

3.如果在ssh到dotcloud并更改了源码,(dotcloud上也要先增加远程库dotcloud ) 如::

$ git commit -a -m “change codes in dotcloud and push to dotcloud remote repo”

$ git push -f –all dotcloud

试着在本地还是dotcloud上执行pull

$ git pull dotcloud
fatal: The remote end hung up unexpectedly

呵呵,行不通吧

===============================================
待续

- EOF -