Set up Git on a PC

Installation

# Linux
sudo apt-get install git
# MAC
brew install git
# Windows
# Download and install "Git for Windows" from the official website (https://gitforwindows.org/).

Set up your account

# xxx.git should be your private repo,
## then you will be asked to input account and git token
git clone xxx.git
  • Follow the Github Docs to get your personal access token: write it down somewhere, otherwise, you will have to generate it again

  • Here is an example what you may see:

Save your credential for future use:

git config --global credential.helper store
  • After this command, you should be able to see there are two files:
    • ~/.gitconfig : This is where your user git configuration file will be saved
    • ~/.git-credentials: this is where your Access token will be saved

Clean your user name and access token:

git config --global --unset credential.helper

If you are using Mac, then this way you probably won’t clean up the credential. So you need to check your git config list by:

git config --list

If you just see:

user.email=zhz03@g.ucla.edu
user.name=Zhaoliang
credential.helper=store

Then the above command will clean up your user name and access token.

However, if you see:

credential.helper=osxkeychain
init.defaultbranch=main
user.email=zhz03@g.ucla.edu
user.name=Zhaoliang

Then your access token will still be there, in this case, you need to check it out:

git config --show-origin --get credential.helper
file:/Applications/Xcode.app/Contents/Developer/usr/share/git-core/gitconfig    osxkeychain

Locate the this file the ‘credential.helper’ configuration in file:/Applications/Xcode.app/Contents/Developer/usr/share/git-core/gitconfig because Git on my computer was automatically installed due to the installation of Xcode software.

Use vim to dd to delete the credential and helper.

Reference

[1] https://www.hi917.com/detail/43.html

[2] https://blog.csdn.net/lynnjinglei/article/details/119025494

[3] https://cloud.tencent.com/developer/article/2207770

[4] Git如何清除和保存本地的用户和密码