我建立了一個名爲project_name/.git的git源代碼庫。
ssh to the server, (entering ssh passwords or passphrases as I go)
mkdir project_name
cd project_name
git init
touch fabfile.py
git add fabfile.py
git commit -a -m "almost empty"
git checkout -b web
我離開分支網站簽出。回到本地機器。
我從服務器通過克隆拉,並添加了我的項目目錄在本地回購分公司主分支。儘管這些步驟也可以自動化,但我並不想使用結構,只是設置了一些東西,而且沒有一個需要另一個SSH密碼。
cd /path/to/project_name/..
git clone ssh://[email protected]_server.com/var/web/project_name/.git
cd project_name
gvim fabfile.py
git add fabfile.py
git commit -a -m "fabfile edits"
現在我開始使用fabric。下面是我的fabfile摘錄管理Git標籤 和分支:
#Usage: fab committag brpush | fab committag push | fab push | fab tag
def committag():
"""commit chgs, tag new commit, push tags to server."""
prompt('commit descr: ', 'COM_MSG', default='new stuff')
prompt('commit name: ', 'COM_NAME', default='0.0.1')
local('git commit -a -m "%(COM_MSG)s"' % env)
local('sleep 1')
local('git tag -u "John Griessen" -m "%(COM_MSG)s" %(COM_NAME)s' % env)
local('sleep 1')
local('git push origin --tags') #pushes local tags
def brpush():
"""create a new branch, default COM_NAME, then push to server."""
prompt('new branch name: ', 'BR_NAME', default= '%(COM_NAME)s' % env)
local('git checkout -b %(BR_NAME)s' % env)
local('sleep 2')
local('git checkout master')
local('git push origin --tags') #pushes local tags
local('git push --all origin') #pushes local master and branches
def push():
"""Push existing tags and changes to server."""
local('git push origin --tags') #pushes local tags
local('git push --all origin') #pushes local master and branches
def tag(): #Call this from committag()
"""create a gpg signed tag on the local git repo tag from prompted name ."""
prompt('tag descr: ', 'TAG_MSG', default='0.0.1')
prompt('tag name: ', 'TAG_NAME', default='0.0.1')
local('git tag -u "John Griessen" -m "%(TAG_MSG)s" %(TAG_NAME)s' % env)
使用上述fabfile DEFS,我只是做一些改變我的項目目錄, 想着它們的apporpriate消息,並做:
$fab committag
我在服務器上標記和更新了更改。或者:
$fab committag brpush
我創建了一個新分支並更新了服務器。
可能重複[如何回答以自動提示與python結構?](http://stackoverflow.com/questions/10479078/how-to-answer-to-prompts-automatically-與蟒蛇織物) – Breedly 2017-02-05 15:11:57