简体   繁体   English

如何为git仓库设置默认的远程源?

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

I'm using hub to create a github repository in command, 我正在使用hub在命令中创建github存储库,

git create -d "Some description"

But without asking me, it automatically add oldUser/repo.git as as remote, Since I'm no longer use oldUser as my github account, how can I change this default behavior to newUser/repo.git 但是,无需询问我,它会自动将oldUser/repo.git添加为远程用户,由于我不再使用oldUser作为我的github帐户,我如何才能将此默认行为更改为newUser/repo.git

Uninstalling and reinstalling should work, but you can also try something like this in ~/.config/hub : 卸载和重新安装应该可以,但是您也可以在~/.config/hub尝试类似的操作:

---
github.com:
- user: new_user

Git comes with a tool called git config that lets you get and set configuration variables that control all aspects of how Git looks and operates. Git附带了一个名为git config的工具,该工具可让您获取和设置配置变量,以控制Git外观和操作的各个方面。 These variables can be stored in three different places: 这些变量可以存储在三个不同的位置:

/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.

On Windows systems, Git looks for the .gitconfig file in the $HOME directory (%USERPROFILE% in Windows' environment), which is C:\\Documents and Settings\\$USER or C:\\Users\\$USER for most people, depending on version ($USER is %USERNAME% in Windows' environment). 在Windows系统上,Git在$ HOME目录(Windows环境中为%USERPROFILE%)中查找.gitconfig文件,对于大多数人来说,该文件为C:\\ Documents and Settings \\ $ USER或C:\\ Users \\ $ USER,具体取决于版本(在Windows环境中,$ USER是%USERNAME%)。 It also still looks for /etc/gitconfig, although it's relative to the MSys root, which is wherever you decide to install Git on your Windows system when you run the installer. 它仍然寻找/ etc / gitconfig,尽管它是相对于MSys根目录的,该根目录是您在运行安装程序时决定在Windows系统上安装Git的位置。

Your Identity The first thing you should do when you install Git is to set your user name and e-mail address. 您的身份安装Git时,您应该做的第一件事就是设置您的用户名和电子邮件地址。 This is important because every Git commit uses this information, and it's immutably baked into the commits you pass around: 这很重要,因为每个Git提交都使用此信息,并且将它不可变地烘焙到您传递的提交中:

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

Again, you need to do this only once if you pass the --global option, because then Git will always use that information for anything you do on that system. 同样,如果您通过--global选项,则只需执行一次,因为Git始终会将该信息用于在该系统上执行的任何操作。 If you want to override this with a different name or e-mail address for specific projects, you can run the command without the --global option when you're in that project. 如果要为特定项目使用其他名称或电子邮件地址覆盖此名称,则在该项目中时可以运行不带--global选项的命令。

Your Editor Now that your identity is set up, you can configure the default text editor that will be used when Git needs you to type in a message. 编辑器既然已经设置了您的身份,您就可以配置默认的文本编辑器,当Git需要您输入消息时将使用该默认文本编辑器。 By default, Git uses your system's default editor, which is generally Vi or Vim. 默认情况下,Git使用系统的默认编辑器,通常是Vi或Vim。 If you want to use a different text editor, such as Emacs, you can do the following: 如果要使用其他文本编辑器(例如Emacs),则可以执行以下操作:

$ git config --global core.editor emacs

Your Diff Tool Another useful option you may want to configure is the default diff tool to use to resolve merge conflicts. 您的差异工具您可能要配置的另一个有用的选项是用于解决合并冲突的默认差异工具。 Say you want to use vimdiff: 假设您要使用vimdiff:

$ git config --global merge.tool vimdiff

Git accepts kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff as valid merge tools. Git接受kdiff3,tkdiff,meld,xxdiff,emerge,vimdiff,gvimdiff,ecmerge和opendiff作为有效的合并工具。 You can also set up a custom tool; 您还可以设置自定义工具。 see Chapter 7 for more information about doing that. 有关更多信息,请参见第7章。

Checking Your Settings If you want to check your settings, you can use the git config --list command to list all the settings Git can find at that point: 检查设置如果要检查设置,可以使用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
...

You may see keys more than once, because Git reads the same key from different files (/etc/gitconfig and ~/.gitconfig, for example). 您可能会多次看到密钥,因为Git从不同的文件(例如,/ etc / gitconfig和〜/ .gitconfig)读取相同的密钥。 In this case, Git uses the last value for each unique key it sees. 在这种情况下,Git使用它看到的每个唯一键的最后一个值。

You can also check what Git thinks a specific key's value is by typing git config {key}: 您还可以通过输入git config {key}来检查Git认为特定键的值是什么:

$ git config user.name
Scott Chacon

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM