Git配置使用者名稱和密碼

2021-10-05 16:48:42 字數 3750 閱讀 1657

一般剛安裝git都要配置使用者名稱和密碼,因為你提交**到本地倉庫(上傳**到遠端倉庫)時會用到,如果沒有沒有配置,在你提交時它會提醒你的。

那麼接下來我們講一下怎麼配置:

目錄1、檢視git的配置列表

2、進行配置

(1)命令列配置

補充:(1.1) 全域性變數

(1.2)區域性變數

注意:區域性變數覆蓋全域性變數!!!和程式語言裡面的變數關係是一樣的。

(2)修改對應檔案進行配置

3、修改已配置的資訊

(1)用命令修改

(2)修改對應檔案進行修改

4、git config命令的功能列表

(1)git config

(2)git config --help

1、檢視git的配置列表

我們可以先檢視一下git的配置列表:

git config --list

如果沒有配置東西,應該是空的。照著下面配置完成後,你可以再試一下該命令,就會出現一系列配置資訊。

2、進行配置

(1)命令列配置

git config --global user.name  "username"  

git config --global user.email  "email"

將username和email換成github(或者其它類似遠端倉庫)的使用者名稱和密碼。

補充:(1.1) 全域性變數

--global  表示全域性的,即當前使用者都有效,該配置會出現在 ~/.gitconfig 檔案中,~表示當前使用者的目錄,比如我的是:c:\users\username\.gitconfig ,開啟該檔案你會發現如下圖所示的內容:

對比一下,你應該就知道上面的配置命令是怎麼起作用的吧(其它配置命令也是這個意思!)。(注:該檔案#開頭的行是注釋,為了方便理解,你可以自己新增一些注釋資訊)

(1.2)區域性變數

既然有全域性的,那麼肯定有區域性的啊!區域性的是不加 --global 的,如下:

git config  user.name  "username"  

git config  user.email  "email"

區域性是只對當前倉庫起效的,它的配置資訊會在當前倉庫根目錄/.git/config檔案下:

注意:區域性變數覆蓋全域性變數!!!和程式語言裡面的變數關係是一樣的。

我在上面我新建的那個倉庫裡,隨便提交了一點東西,然後檢視提交日誌如下:

(2)修改對應檔案進行配置

相信看了上面的補充內容之後,你應該已經了解這兩個配置命令的作用了吧,所以這裡就不詳講了,你找到對應檔案,該相關設定就好了。

3、修改已配置的資訊

假如配置後,發現有資訊配置錯了,如何進行修改?

(1)用命令修改

git config --replace-all user.name "name"

git config --replace-all user.email "[email protected]"

修改後是這樣的:

(2)修改對應檔案進行修改

這個應該不用講了。

4、git config命令的功能列表

(1)git config

我們直接輸入git config,就可以看到簡單的命令列表了:

$ git config

usage: git config

config file location

--global              use global config file

--system              use system config file

--local               use repository config file

--worktree            use per-worktree config file

-f, --file use given config file

--blob read config from given blob object

action

--get                 get value: name [value-regex]

--get-all             get all values: key [value-regex]

--get-regexp          get values for regexp: name-regex [value-regex]

--get-urlmatch        get value specific for the url: section[.var] url

--replace-all         replace all matching variables: name value [value_regex]

--add                 add a new variable: name value

--unset               remove a variable: name [value-regex]

--unset-all           remove all matches: name [value-regex]

--rename-section      rename section: old-name new-name

--remove-section      remove a section: name

-l, --list            list all

-e, --edit            open an editor

--get-color           find the color configured: slot [default]

--get-colorbool       find the color setting: slot [stdout-is-tty]

type

-t, --type <>         value is given this type

--bool                value is "true" or "false"

--int                 value is decimal number

--bool-or-int         value is --bool or --int

--path                value is a path (file or directory name)

--expiry-date         value is an expiry date

other

-z, --null            terminate values with nul byte

--name-only           show variable names only

--includes            respect include directives on lookup

--show-origin         show origin of config (file, standard input, blob, command line)

--default with --get, use default value when missing entry

(2)git config --help

這個命令預設開啟本地git安裝目錄下的g:\git\mingw64\share\doc\git-doc\下的詳細的說明文件(這裡g:\git為安裝目錄),這個是詳細介紹命令的作用(上面的那個只是簡介)。

樣例截圖:

Git配置使用者名稱密碼

在linux下和windows下配置git的方法差不多,只是在linux下,可以在命令列裡直接使用git config進行配置,而在windows下則要先開啟 git bash 進入msysgit命令列介面,再用git config命令進行相應的配置操作。好了,前面安裝好了git,現在我們開始配置 ...

Git 配置使用者名稱 郵箱 密碼

git config global user.name usernamegit config global user.email user emailgit config global credential.helper store該命令會記住密碼,執行一次 git pull 或 git push ...

git本地配置使用者名稱 git配置全域性使用者名稱

在使用idea開發的過程中,提交時遇到兩個問題,乙個是每次提交都需要輸入使用者名稱和密碼,選擇記住密碼,依然提示 第二個是提交後,git賬戶名顯示是administrator,跟自己註冊git時賬號不一致,今天花了點時間,從網上找了下解決方案,記錄一下。1.處理不用反覆輸入密碼問題 開啟git終端,...