Git

Highlights

Setup after Reboot

SSH Key authentication is needed because username/password authentication is no longer supported. Make sure the ssh key already created; see Create SSH Key;

$ eval "$(ssh-agent -s)"
$ ssh-add -l
$ ssh-add ~/.ssh/id_rsa_gabepublic
Enter passphrase for /home/gabe/.ssh/id_rsa_gabepublic:
Identity added: /home/gabe/.ssh/id_rsa_gabepublic (gabe.public@outlook.com)
$ ssh -T git@github.com
$ git clone git@github.com:gabepublic/llm-chainlit.git
Frequent used commands
  • Clone, Pull, Checkin & Push

git clone git@github.com:gabepublic/aws-ec2-docker.git
cd aws-ec2-wocker
git pull
# checkin
git add *
git commit -am "commit message"
git push -u origin main

Setup (debian)

Git is pre-installed on WSL Ubuntu

Support for password authentication was removed on August 13, 2021.

Configure

  • Set account default identity

$ git config --global user.email "you@example.com"
$ git config --global user.name "Your Name"

Developer flow

# init git repo
$ git init
# or clone if the repo exists already
$ git clone https://..
# basic dev flow
$ git status
$ git add *
$ git commit -am "commit message"
$ git pull --verbose
$ git remote -v
$ git remote get-url origin
# Repo needs to be created in github first
$ git remote add origin git@github.com:username/reponame.git
$ git config --global pull.rebase false     # if not done before
$ git pull origin main --allow-unrelated-histories
$ git branch -M main   # rename from master to main, I think!!
$ git push -u origin main

# config
$ git config --global user.name "Mona Lisa"
$ git config -l
$ cat ~/.gitconfig

# branching; see REF-3
$ git branch -[dv] -all
$ git branch <newBranchName>
$ git checkout <newBranchName>
$ git checkout -b <newBranchName>
# making changes in <newBranchName>
$ git checkout main
$ git merge <newBranchName>
$ git branch -d <newBranchName>    # delete the branch 

Start a new Github repo

Git Credential Manager

Source: - Git Credential Manager - Creating a personal access token

  • Install

$ cd ~
$ curl -LO https://raw.githubusercontent.com/GitCredentialManager/git-credential-manager/main/src/linux/Packaging.Linux/install-from-source.sh
$ sh ./install-from-source.sh
$ git-credential-manager-core configure
  • Setup

$ git-credential-manager-core diagnose
$ git config --global credential.credentialStore cache

$ cd ~/projects/<repo_name>
$ git push origin main
// The first time or after cache memory expire
Select an authentication method for 'https://github.com/':
  1. Device code (default)
  2. Personal access token
option (enter for default): 2
Enter GitHub personal access token for 'https://github.com/'...
Token:
Enumerating objects: 14, done.
Counting objects: 100% (14/14), done.
Delta compression using up to 4 threads
Compressing objects: 100% (10/10), done.
Writing objects: 100% (13/13), 2.49 KiB | 1.25 MiB/s, done.
Total 13 (delta 0), reused 0 (delta 0)
To https://github.com/gabepublic/aws-cdk-py-s3-01.git
   68a80cd..6ccb35b  main -> main
$ 

Error: fatal: Response status code does not indicate success: 401 (Unauthorized).

The error occurs while doing git push or git clone of private repo.

Possible reason: the "personal access token" is configured with expiration or no-expiration. The error may result from expired token.

Create SSH Key

RELATED: SETUP > Dev Environments > SSH |

  • On the Linux host, create the ssh key (public & private)

$ cd ~
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
$ ls -al ~/.ssh
[...]
-rw-------  1 gabe gabe 3434 Aug  7  2023 id_rsa_gcloudex
-rw-r--r--  1 gabe gabe  744 Aug  7  2023 id_rsa_gcloudex.pub
  • Add to ssh-agent

$ eval "$(ssh-agent -s)"
Agent pid 5416
$ ssh-add ~/.ssh/id_rsa
Enter passphrase for /home/gabe/.ssh/id_rsa: 
Identity added: /home/gabe/.ssh/id_rsa (gcloudex@gmail.com)
$ ssh -T git@github.com
$ git clone git@github.com:<username>/<repo>.git

References:

Connecting to GitHub with SSH

Source: https://docs.github.com/en/authentication/connecting-to-github-with-ssh

Useful topics:

  • About SSH

  • Generating a new SSH key and adding it to the ssh-agent

  • Adding a new SSH key to your GitHub account

  • Testing your SSH connection

Add topic(s) to the repo to enable better search of repositories.

  • Go to the repository. On the righthand side, About, click the Settings

  • Add Topics

To search based on topic(s), for example, enter the following to the Github page - "Search or jump to...":

user:<username> topic:docker topic:api

Semantic Versioning

Source: http://semver.org/

Tool for testing Semantic Versioning: https://github.com/npm/node-semver

Gist

Search my own gist: on the "Your gists" page, enter the following to the search box:

user:gabepublic parser

How-to

Compare Files with Git Diff Tool
Download a file from Github repo
$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
$ unzip awscliv2.zip
Split a folder and create new repo
$ git clone https://github.com/samples/webapp-workshop.git
$ cd webapp-workshop
$ sudo yum install git-subtree -y
$ git subtree split -P code/webapp -b Webapp
$ mkdir ../webapp-only && cd ../webapp-only
$ git init
$ git pull ../webapp-workshop Webapp
# assuming the github repo already created
$ git remote add origin https://github.com/OWNER/REPOSITORY.git
$ git push -u origin master
$ rm -rf ../webapp-workshop
Setup after reboot
$ eval "$(ssh-agent -s)"
$ ssh-add -l
  • re-add the ssh key

$ ssh-add ~/.ssh/id_rsa_gabepublic
Enter passphrase for /home/gabe/.ssh/id_rsa_gabepublic:
Identity added: /home/gabe/.ssh/id_rsa_gabepublic (gabe.public@outlook.com)
  • Test connection

$ ssh -T git@github.com
  • Now, should be able to clone private repo

$ git clone git@github.com:gabepublic/llm-chainlit.git
  • Note: may need to do after each Windows reboot

References

Last updated