git push 免密碼提交 github


git

1. git push 免密碼

通用情況

  1. 使用文件創建用戶名和密碼

文件創建在用戶主目錄下:

touch .git-credentials
vim .git-credentials
https://{username}:{password}@github.com 

記得在真正輸入的時候是沒有大括號的。

  1. 添加 git config 內容

git config --global credential.helper store

執行此命令后,用戶主目錄下的.gitconfig 文件會多了一項:[credential]

helper = store

重新 git push 就不需要用戶名密碼了。

使用 ssh 協議

首先生成密鑰對:

ssh-keygen -t rsa -C "youremail"

接下來按照提示操作,默認可以一路往下。

然后將生成的位於~/.ssh/id_rsa.pub的內容復制到你 github setting 里的 ssh key 中。

復制之后,如果你還沒有克隆你的倉庫,那你直接使用 ssh 協議用法:git@github.com:yourusername/yourrepositoryname克隆就行了。

如果已經使用 https 協議克隆了,那么按照如下方法更改協議: git remote set-url origin git@github.com:yourusername/yourrepositoryname.git

Done!


2. git add 使用 tab 鍵自動補全的中文文件名亂碼

文件名亂碼如下所示:

 

亂碼

 

解決方法為:

git config --global core.quotepath false

效果如下:

 

效果

 

可以看出中文已經正確顯示了。


3. git 遷移倉庫到另外一個倉庫

# 僅保留歷史提交信息 git clone --bare yourrepository 

然后在你的其他服務,比如 gogs 新建一個倉庫,然后進入你上步克隆出的倉庫中,執行:

git push --mirror yourNewRepository

然后你就可以刪除原來的倉庫,然后git clone新倉庫就行了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM