Playing with git and GitHub

Playing with git and GitHub

·

4 min read

Generate a token from GitHub remote repository via -->

  1. Check the value of the origin variable which is the URL of my GitHub repo

git remote -v

origingithub.com/Titir250/devops-journey.git(fetch)

origingithub.com/Titir250/devops-journey.git(push)

Copy the token from remote GitHub repository

Click on settings

Click on Developer settings

Click on tokens(classic) preferably and then Generate a new token. In the token settings fill up desired access, expiry date and once the token is generated copy it and save it.

  1. Now change the origin URL value with the new token generated by GitHub.Add the token value then @github……..

git remote -v set-url origin*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@gi..

3.Now the value is changed so when we do push it will hit the new URL with the token

git remote -v

originghpo3mw5z9YAmNNvLQr980VaqZ0gx6i0W0cDcRi@git..(fetch)

originghpo3mw5z9YAmNNvLQr980VaqZ0gx6i0W0cDcRi@git..(push)

4.Now the new changes in the local is pushed to the remote repository using git push command

git push origin main

Enumerating objects: 4, done.

Counting objects: 100% (4/4), done.

Delta compression using up to 8 threads

Compressing objects: 100% (2/2), done.

Writing objects: 100% (3/3), 314 bytes | 314.00 KiB/s, done.

Total 3 (delta 1), reused 0 (delta 0), pack-reused 0

remote: Resolving deltas: 100% (1/1), completed with 1 local object.

Togithub.com/Titir250/devops-journey.git

90f6c96..16f01ff main -> main

clone

Clone a GitHub remote repository using https protocol -->

  1. Open GitHub remote repository and copy the path under the clone section below https.

  1. Go to your local file system and run git clone command.

git clonegithub.com/Titir250/glearning-git-session.git

Cloning into 'glearning-git-session'...

remote: Enumerating objects: 13, done.

remote: Counting objects: 100% (13/13), done.

remote: Compressing objects: 100% (8/8), done.

remote: Total 13 (delta 1), reused 11 (delta 0), pack-reused 0

Receiving objects: 100% (13/13), done.

Resolving deltas: 100% (1/1), done.

ls

devops-journey glearning-git-session

Clone a GitHub remote repository using ssh key pair-->

  1. GitHub remote repository and copy the path under the clone section below ssh.

  1. Try to clone using git clone shows an error permission denied because there is no ssh key generated in my local system which is not known by github.

git clone:Titir250/devops-journey.git

Cloning into 'devops-journey'...

The authenticity of host 'github.com(20.207.73.82)' can't be established.ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.

This key is not known by any other names

Are you sure you want to continue connecting (yes/no/[fingerprint])? yes

Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.

: Permission denied (publickey).

fatal: Could not read from remote repository.

Please make sure you have the correct access rights

and the repository exists.

  1. Generate a pair of ssh key using the ssh-keygen method and copy the public key from there.

I. Go to the ./ssh folder to generate the new ssh key pair.

cd .ssh

ssh-keygen

Generating public/private rsa key pair.

Enter file in which to save the key (/home/titir/.ssh/id_rsa): github_key

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in github_key

Your public key has been saved in github_key.pub

The key fingerprint is:

SHA256:GJyi/g6Hy+pnVNFKW6lGKflCj++uhV+bk/v7JPVNznY titir@Titir

The key's randomart image is:

+---[RSA 3072]----+

| . o . |

| + \ = |*

| . O X |

| + X o |

| . = . S . . |

| . o.. . . = |

| =.o. ... . . =E|

| . Bo..oo o . .|

|oo=o=o ++oo. |

+----[SHA256]-----+

Now 2 keys github_keyandgithub_key.pubprivate key and public key respectivelyare generated.

ls

github_key github_key.pub known_hosts

II. Copy the public key github_key.pub.

cat github_key.pub

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCmbBArUi0801QW71DbF1PM1PDEjaG5oBTv83XHDt7gSLnmkoiddgs9AC3FSWfMNxaTVprZBpTjNHc66kDdKAEhoQpjMGkQZhrc9+MEibUXBOsoaOp2tPgEO4wk636rsW1t/3yJv7cGWvJJcdDG8vO+jT6jVNW+GR9gs3VU51zRAGiYu9T7sead4Ax5ZVyE3lD4JA2jWtDfJrQp/B3mHT2A0zu8aDNEhvw77CLPIKjP5SZ08wSS7wG7kYb/u2ce+fMS1kzKv29mWsV9+mruLuuhyK2n8sErLAa253+u8BSnPrzGrH5Ebvy6bhl6o20Gs1M4IDaVUusH5RbQhWRLg8Xoa3TwCmLNQFoEkG8Zx0n3xHkpTT6bba6Pk5V/GwssUaVYk/+8jrUyLQJNaWBrlpKvbaiWlwp+WQRL5qZdr/pL2DJgxfHFHCua5SBre+A9z2tCgP3KcG5RZ0pbExcZY3DP/7pRDQ9KyqiPxStgM79Clxo0Xotesj+zVWRi8jxIi80= titir@Titir

  1. Go to GitHub remote repository and paste the public key value there.

Go to GitHub settings and the SSH and GPG keys and click on new ssh key and save the generated public key there.

  1. Now go to your local git repository and run the below command to successfully clone the remote git repository.

GIT_SSH_COMMAND="ssh -i /home/titir/.ssh/github_key" git clone:Titir250/devops-journey.git

Cloning into 'devops-journey'...

remote: Enumerating objects: 12, done.

remote: Counting objects: 100% (12/12), done.

remote: Compressing objects: 100% (6/6), done.

Receiving objects: 100% (12/12), done.

remote: Total 12 (delta 2), reused 4 (delta 1), pack-reused 0

Resolving deltas: 100% (2/2), done.