簡體   English   中英

如何為git倉庫設置默認的遠程源?

[英]How to set default remote origin for git repository?

我正在使用hub在命令中創建github存儲庫,

git create -d "Some description"

但是,無需詢問我,它會自動將oldUser/repo.git添加為遠程用戶,由於我不再使用oldUser作為我的github帳戶,我如何才能將此默認行為更改為newUser/repo.git

卸載和重新安裝應該可以,但是您也可以在~/.config/hub嘗試類似的操作:

---
github.com:
- user: new_user

Git附帶了一個名為git config的工具,該工具可讓您獲取和設置配置變量,以控制Git外觀和操作的各個方面。 這些變量可以存儲在三個不同的位置:

/etc/gitconfig file: Contains values for every user on the system and all their repositories. If you pass the option--system to git config, it reads and writes from this file specifically.

~/.gitconfig file: Specific to your user. You can make Git read and write to this file specifically by passing the --global option.

config file in the git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository. Each level overrides values in the previous level, so values in .git/config trump those in /etc/gitconfig.

在Windows系統上,Git在$ HOME目錄(Windows環境中為%USERPROFILE%)中查找.gitconfig文件,對於大多數人來說,該文件為C:\\ Documents and Settings \\ $ USER或C:\\ Users \\ $ USER,具體取決於版本(在Windows環境中,$ USER是%USERNAME%)。 它仍然尋找/ etc / gitconfig,盡管它是相對於MSys根目錄的,該根目錄是您在運行安裝程序時決定在Windows系統上安裝Git的位置。

您的身份安裝Git時,您應該做的第一件事就是設置您的用戶名和電子郵件地址。 這很重要,因為每個Git提交都使用此信息,並且將它不可變地烘焙到您傳遞的提交中:

$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com

同樣,如果您通過--global選項,則只需執行一次,因為Git始終會將該信息用於在該系統上執行的任何操作。 如果要為特定項目使用其他名稱或電子郵件地址覆蓋此名稱,則在該項目中時可以運行不帶--global選項的命令。

編輯器既然已經設置了您的身份,您就可以配置默認的文本編輯器,當Git需要您輸入消息時將使用該默認文本編輯器。 默認情況下,Git使用系統的默認編輯器,通常是Vi或Vim。 如果要使用其他文本編輯器(例如Emacs),則可以執行以下操作:

$ git config --global core.editor emacs

您的差異工具您可能要配置的另一個有用的選項是用於解決合並沖突的默認差異工具。 假設您要使用vimdiff:

$ git config --global merge.tool vimdiff

Git接受kdiff3,tkdiff,meld,xxdiff,emerge,vimdiff,gvimdiff,ecmerge和opendiff作為有效的合並工具。 您還可以設置自定義工具。 有關更多信息,請參見第7章。

檢查設置如果要檢查設置,可以使用git config --list命令列出Git可以找到的所有設置:

$ git config --list
user.name=Scott Chacon
user.email=schacon@gmail.com
color.status=auto
color.branch=auto
color.interactive=auto
color.diff=auto
...

您可能會多次看到密鑰,因為Git從不同的文件(例如,/ etc / gitconfig和〜/ .gitconfig)讀取相同的密鑰。 在這種情況下,Git使用它看到的每個唯一鍵的最后一個值。

您還可以通過輸入git config {key}來檢查Git認為特定鍵的值是什么:

$ git config user.name
Scott Chacon

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM