Git associated

Delete folder association with Git

rm -rf .git
Copy the code

Then there is an error associated with remote or push, as follows:

fatal: Not a git repository (or any of the parent directories): .git 
Copy the code

For a directory like git, type git init and press Enter

git init
Copy the code

Example Modify the remote warehouse address

It is recommended that you delete it before adding it

  1. Example Delete the remote warehouse address
git remote rm origin
Copy the code
  1. Add a new Git repository address
Git remote add Origin Specifies the repository addressCopy the code

Resolve code base forks

Git rebase -i commitid git rebase -i commitid git push --forceCopy the code

Add & remove tags

View all tags

git tag -l
Copy the code

Add the tag

git tag -a tagName -m 'my tag'
git push origin --tags
Copy the code

Remove the tag

git tag -d tagName
Copy the code

Clear all commit logging methods

Scenario: When you commit code to a Git repository, you need to delete the commit record to completely clean up the commit information and get a clean repository with the code unchanged

  1. Establish a rootless branch (through--orphanThe ‘latest_branch’ branch created has no parent.)
git checkout --orphan latest_branch
Copy the code
  1. Add all files
git add -A
Copy the code
  1. Commit the changes
git commit -am 'commit message'
Copy the code
  1. Delete the branch
git branch -D master
Copy the code
  1. Rename the current branch to master
git branch -m master
Copy the code
  1. Force updates to the code base (requires administrator privileges)
git push -f origin master
Copy the code

Git configures multiple SSH keys

Scenario: Sometimes our code needs to be hosted on multiple platforms, and we need to set the SSH-key for each hosting platform

Open the git bash:

  1. Ssh-key $ssh-keygen -t rsa -c “[email protected]” -f ~/. SSH /id_rsa

  2. Ssh-key $ssh-keygen -t rsa -c “[email protected]” -f ~/. SSH /github_rsa Pub, github_rsa, id_RSA, id_rsa.pub, respectively configure the contents of their public key files (github_rsa.pub, id_rsa.pub) to the corresponding code repository

    Configure the public key: Log in to Github or another code hosting platform. In the upper right corner, click Settings for your login profile

    Click SSH and GPG keys

    ssh-keygen -t rsa -C "[email protected]" -f ~/.ssh/github_rsa
    Copy the code

    Finally, click Add Key to save

  3. Add the private key

    $ ssh-add ~/.ssh/id_rsa  $ ssh-add ~/.ssh/github_rsa
    Copy the code

    If “Could not open a connection to your authentication agent” is displayed during the ssh-add command, run the following command:

    $ ssh-agent bash
    Copy the code

    Then run the ssh-add command again:

    $ ssh-add ~/.ssh/id_rsa  $ ssh-add ~/.ssh/github_rsa
    Copy the code

    We can confirm the list of private keys by using ssh-add-l

    $ ssh-add -l
    Copy the code

    To delete the private key list, run the ssh-add -d command

    $ ssh-add -D
    Copy the code
  4. test

    $ ssh -T [email protected]
    Copy the code
    1. Permission denied

    ssh-keygen -t rsa -C "[email protected]" -f ~/.ssh/github_rsa
    ssh -v [email protected]
    ssh-agent -s 
    ssh-add ~/.ssh/github_rsa
    ssh -T [email protected]
    Copy the code
    1. retry

    Authentication passed