1. Go to .ssh folder into C:\Users\HP\.ssh
2. Open Git Bash command
3. To generate SSH key :
ssh-keygen -t rsa -f id_rsa_xxxxxx
4.Open id_rsa_lookman.pub key file in notepad and Ctr+A copy the full file then paste it into Github SSH Key box
5. To add Private key to SSH agent / Add IdentityFile :
ssh-add ~/.ssh/id_rsa_xxxxxx
6. Verify that private key has been added successfully :
ssh-add -l
7. Go to config file in same floder and edit it :
Host github_sshname
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_xxxxxx
8. Clone the repository :
git clone git@:/.git
git clone git@github_sshname:gitusername/abc-mail.git
git remote set-url origin https://github.com/prabha*****/hmis-mail.git
9. Remove last commit :
git push -f origin HEAD^:main
—
List all variables set in the config file, along with their values.
git config --list
If you are new to git then use the following commands to set a user name and email address.
Set user name
git config --global user.name "your Name"
Set user email
git config --global user.email "your_email@example.com"
Check user name
git config user.name
Check user email
git config user.email
—
Git config variables can be stored in 3 different levels. Each level overrides values in the previous level.
1. System level (applied to every user on the system and all their repositories)
to view, git config –list –system (may need sudo)
to set, git config –system color.ui true
to edit system config file, git config –edit –system
2. Global level (values specific personally to you, the user. )
to view, git config –list –global
to set, git config –global user.name xyz
to edit global config file, git config –edit –global
3. Repository level (specific to that single repository)
to view, git config –list –local
to set, git config –local core.ignorecase true (–local optional)
to edit repository config file, git config –edit –local (–local optional)
How to view all settings?
Run git config –list, showing system, global, and (if inside a repository) local configs
Run git config –list –show-origin, also shows the origin file of each config item
How to read one particular config?
Run git config user.name to get user.name, for example.
You may also specify options –system, –global, –local to read that value at a particular level.
Adding a remote repository
$ git remote add origin https://github.com/OWNER/REPOSITORY.git
# Set a new remote
$ git remote -v
# Verify new remote
> origin https://github.com/OWNER/REPOSITORY.git (fetch)
> origin https://github.com/OWNER/REPOSITORY.git (push)
——-
Switching remote URLs from SSH to HTTPS
$ git remote -v
> origin git@github.com:OWNER/REPOSITORY.git (fetch)
> origin git@github.com:OWNER/REPOSITORY.git (push)
$ git remote set-url origin https://github.com/OWNER/REPOSITORY.git
$ git remote -v
# Verify new remote URL
> origin https://github.com/OWNER/REPOSITORY.git (fetch)
> origin https://github.com/OWNER/REPOSITORY.git (push)
——–
Renaming a remote repository
$ git remote -v
# View existing remotes
> origin https://github.com/OWNER/REPOSITORY.git (fetch)
> origin https://github.com/OWNER/REPOSITORY.git (push)
$ git remote rename origin destination
# Change remote name from ‘origin’ to ‘destination’
$ git remote -v
# Verify remote’s new name
> destination https://github.com/OWNER/REPOSITORY.git (fetch)
> destination https://github.com/OWNER/REPOSITORY.git (push)
——
Removing a remote repository
Removing the remote URL from your repository only unlinks the local and remote repositories. It does not delete the remote repository.
$ git remote -v
# View current remotes
> origin https://github.com/OWNER/REPOSITORY.git (fetch)
> origin https://github.com/OWNER/REPOSITORY.git (push)
> destination https://github.com/FORKER/REPOSITORY.git (fetch)
> destination https://github.com/FORKER/REPOSITORY.git (push)
$ git remote rm destination
# Remove remote
$ git remote -v
# Verify it’s gone
> origin https://github.com/OWNER/REPOSITORY.git (fetch)
> origin https://github.com/OWNER/REPOSITORY.git (push)