Git useage
Init a git project on GitHub
bash
mkdir my_pro
cd my_pro
echo "# My_Pro" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/yourusername/repo.git
git push -u origin mainmkdir my_pro
cd my_pro
echo "# My_Pro" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/yourusername/repo.git
git push -u origin mainUninstall Git totally
- delete the
Gitfrom your PC. - delete all .gitconfig, please read this.
- run below code to find out all
.gitconfigfiles, then delete them.
- run below code to find out all
bash
git config --list --show-origingit config --list --show-originRe-install Git
- If there is Git's per-user configuration file.
bash
git config --global --editgit config --global --edit- After change the old user info to your new git user info, then run:
bash
git commit --amend --reset-authorgit commit --amend --reset-author- Then setup your info
bash
git config --global user.name "Your Name"
git config --global user.email you@example.com
git commit --amend --reset-authorgit config --global user.name "Your Name"
git config --global user.email you@example.com
git commit --amend --reset-authorChange the remote url
- Syntax
sh
git remote set-url <remote_name> <remote_url>git remote set-url <remote_name> <remote_url>- Example for Edit origin url
sh
git remote set-url origin https://git-repo/new-repository.gitgit remote set-url origin https://git-repo/new-repository.git- Check local remote
sh
git remote -vgit remote -vChange local PC account
- Check your current configuration
sh
git config --listgit config --listUpdate Global Configuration (Optional)
If you're switching to a new GitHub account permanently, you might want to update your global Git configuration with your new username and email. You can do this by using the following commands:
sh
git config --global user.name Your_New_Username
git config --global user.email yournewemail@example.comgit config --global user.name Your_New_Username
git config --global user.email yournewemail@example.comChange Repository Configuration
If you only want to change the GitHub account for a specific repository, navigate to the repository's directory in your terminal and use the following commands:
sh
git config user.name Your_New_Username
git config user.email yournewemail@example.comgit config user.name Your_New_Username
git config user.email yournewemail@example.com