git便捷設置

咱們知道git本地和遠程倉庫之間有兩種鏈接方式,https和ssh,以下git

其中HTTPS方式,在往遠程推代碼的時候,都須要鍵入用戶名和密碼,很是麻煩,這裏能夠經過一個小設置來免除這種麻煩。github

步驟以下:vim

1, 建立文件

cd ~
touch .git-credentials

2,添加內容

vim .git-credentials

填入信息bash

https://{username}:{password}@{github.com/gitlab.com}

其中{username}爲你的github或者所在gitlab的帳號用戶名, {password}爲你的帳號密碼, {github.com/gitlab.com}爲你的項目的github或gitlab地址,app

ssh

https://{abc}:{defg}@{hijk.gitlab.com/lmn/opq}

3,添加git配置

git config --global credential.helper store

4,驗證

這時候在.gitconfig文件中就能夠看到gitlab

vi .gitconfig

[user]
        name = abc
        email = abc@1111.com
[credential]
        helper = store

會在你輸入帳號信息後進行保存,之後提交就不用再輸入了。fetch

 

操做命令簡寫

爲了減小拼寫git命令的時間,咱們能夠使用一些簡寫命令,一樣的在~/.gitconfig文件中,根據本身的須要進行增減修改,以下:ui

[merge]
    summary = true
    tool = vimdiff
[diff]
    renames = copy
[color]
    diff = auto
    status = true
    branch = auto
    interactive = auto
    ui = auto
    log = true
[status]
    submodulesummary = -1
[mergetool "vimdiff"]
    cmd = "vim --noplugin \"$PWD/$MERGED\" \
          +\":split $PWD/$REMOTE\" +\":set buftype=nowrite\" \
          +\":vertical diffsplit $PWD/$LOCAL\" +\":set buftype=nowrite\" \
          +\":vertical diffsplit $PWD/$BASE\" +\":set buftype=nowrite\" \
          +\":wincmd l\""
[format]
    numbered = auto
[alias]
    co = checkout
    ci = commit
    st = status
    pl = pull
    ps = push
    dt = difftool
    l = log --stat
    cp = cherry-pick
    ca = commit -a
    b = branch
    pso = push origin
    plo = pull origin
    cm = commit -m
    gst = git status
    gd = git diff
    gl = git pull
    gp = git push
    glo = git pull origin
    gpo = git push origin
    gcm = git common -m
    gc = git checkout
    gcm = git checkout master
    gcd = git checkout develop
    gb = git branch
    ga = git add .
[user]
        name = hanya
        email = hanya-mac@xiaomi.com
[core]
        excludesfile = /Users/hanya/.gitignore_global
[difftool "sourcetree"]
        cmd = opendiff \"$LOCAL\" \"$REMOTE\"
        path =
[mergetool "sourcetree"]
        cmd = /Applications/SourceTree.app/Contents/Resources/opendiff-w.sh \"$LOCAL\" \"$REMOTE\" -ancestor \"$BASE\" -merge \"$MERGED\"
        trustExitCode = true

(參考https://blog.csdn.net/maitiandaozi/article/details/51556323)url

 

切換SSH和HTTPS的方式以下

1, 在你的開發分支下面輸入

git remote -v
origin	https://gitlab.abc.com/PHP/defg.git (fetch)
origin	https://gitlab.abc.com/PHP/defg.git (push)

能夠看到當前你在使用哪一種方式。

2, 從HTTPS切到SSH

git remote set-url origin git@gitlab.abc.com/PHP/defg.git

3, 從SSH切到HTTPS

git remote set-url origin https://gitlab.abc.com/PHP/defg.git

能夠在切換後使用git remote -v來查看校驗。

相關文章
相關標籤/搜索