2017-09-22 28 views
0
git push -u origin <branch> 

當您運行此命令到位桶,它給你的輸出一樣,如何混帳推命令的輸出的所有行存儲到位桶

Counting objects: 
remote: 
remote: Create pull request for <branch> 
remote: https://bitbucket.com/... 

但是當我嘗試存儲輸出在變量和打印該變量,它給了我這樣的輸出,

a=$(git push -q -u origin <branch>) 
echo $a 
Branch <branch> set up to track remote branch <branch> from origin. 

我想存儲上面的輸出或我只想說拉請求的URL存儲到一個變量。

拉取請求URL是首選的選項。 謝謝

+0

小記:這是bitbucket.org。 Bitbucket.com只是重定向。 –

回答

2

您可以將git輸出存儲到一個文件:

git push -u origin mybranch &> /tmp/git-push-origin-mybranch.txt 

,然後存儲內容到一個變量

git_result=$(cat /tmp/git-push-origin-mybranch.txt) 
+0

有什麼辦法只得到該網址? @gogaz –

+0

@MithilAmin從.git/config讀取它呢? – gogaz