Git - setup and tips

Quick notes

Git - setup and tips

Quick notes

Git Setup

I do this quite rarely, so next time I (or some who I need to help on this) will find instructions here (2020-11-15-Git_setup.md).

T430

$ git clone https://github.com/talonendm/talonendm.github.io.git
$ git status
$ git add .
  • warning: CRLF will be replaced by LF in _posts/2020-11-15-Git_setup.md. The file will have its original line endings in your working directory
  • ok: https://stackoverflow.com/questions/5834014/lf-will-be-replaced-by-crlf-in-git-what-is-that-and-is-it-important
 git commit -m "git instructions"

Author identity unknown

*** Please tell me who you are.

Run

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

Git instructions, see e.g. Getting started.

$git config --global user.email <gmail-account-without brackets
$git config --global user.name "Jaakko T430"

$ git config user.name
Jaakko T430

Let’s try again:

$ git commit -m "git instructions"
$ git push origin master

First time you need to authorize your self with browser. Use your github credentials. Finally you get message: “Authentication Succeeded. You may now close this tab and return to the application.”

T530

Another laptop:

Git setup:

  • defaults except, I changed this: “Use Vim (the umbigious text editor) as Git’s default editor” to this: “use Notepad++ as Git’s default editor”
mkdir git

git config --global user.email talonen.dm@gmail.com
git config --global user.name "Jaakko T530"

git config user.name

git clone https://github.com/talonendm/talonendm.github.io.git
pwd

I edited this file…

cd talonendm.github.io/
git status
git add _posts/2020-11-15-Git_setup.md
git commit -m "some git setup notes"
git push origin master

select sign in with your browser.

Desktop Asus 12/2021

Users / Kayttajat / username talon. Default foldet for Bash.


pwd
mkdir git
cd git
git clone https://github.com/talonendm/talonendm.github.io.git

git clone https://github.com/talonendm/talonendm.github.io.git

git config --global user.email talonen.dm@gmail.com
git config --global user.name "Jaakko Asus"

git config user.name # check username

pwd

Git tips

“undo”

You can undo git add before commit with, see more detail here

git add .
git reset <path/file>

OR

git reset HEAD myfile.txt
git status

error messages

  • “The file will have its original line endings in your working directory warning: CRLF will be replaced by LF in”: “In Unix systems the end of a line is represented with a line feed (LF). In windows a line is represented with a carriage return (CR) and a line feed (LF) thus (CRLF). when you get code from git that was uploaded from a unix system they will only have an LF.”, see more details in stackoverflow

If you want, you can deactivate this feature in your git core config using first and the latter one to get rid of the warnings using.

$ git config core.autocrlf false
$ git config core.autocrlf true

Note: Latter one used 12.6.2021 on T530 (not working?) as

talon_000@T530_2017_JT MINGW64 ~/git/talonendm.github.io (master)
$ git config core.autocrlf true # not working

$ git config --global core.autocrlf true
 git commit -m "fix #3 - version log to md added"

 or

 git commit -m "close #2 - feature added"

Build version node.js 240624: Beautiful Jekyll CI: All jobs have failed

Not working… todo: Fetch the latest changes from the original repository, see June GPT discussion.

name: Beautiful Jekyll CI
on: [push, pull_request]
jobs:
  build:
    name: Build Jekyll
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Build the site in the jekyll/builder container
        run: |
          export JEKYLL_VERSION=3.8
          docker run \
          -v $:/srv/jekyll -v $/_site:/srv/jekyll/_site \
          -e PAGES_REPO_NWO=$ \
          jekyll/builder:$JEKYLL_VERSION /bin/bash -c "chmod 777 /srv/jekyll && jekyll build --future"

Build Jekyll Node.js 16 actions are deprecated. Please update the following actions to use Node.js 20: actions/checkout@v3. For more information see: https://github.blog/changelog/2023-09-22-github-actions-transitioning-from-node-16-to-node-20/.

Changed to based on node v20 info

name: Beautiful Jekyll CI
on: [push, pull_request]
jobs:
  build:
    name: Build Jekyll
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Build the site in the jekyll/builder container
        run: |
          export JEKYLL_VERSION=3.8
          docker run \
          -v $:/srv/jekyll -v $/_site:/srv/jekyll/_site \
          -e PAGES_REPO_NWO=$ \
          jekyll/builder:$JEKYLL_VERSION /bin/bash -c "chmod 777 /srv/jekyll && jekyll build --future"

Multiple GitHub Accounts - one computer

  • youtube: TruthSeekers
  • stackoverflow
  • ssh-keygen -t rsa -C “main_email@gmail.com”
  • go to .ssh folder and copy
    • copy content of id_rsa.pub to GitHub-settings keys.
    • Desktop Home - Acer = created
    • add it to ssh agent as:
      • run this if ssh-add not working: ssh-agent bash stackover
      • ssh-add id_rsa
      • $ ssh-add id_rsa –> Identity added: id_rsa (main_email@gmail.com)
  • ssh-keygen -t rsa_vaaka -C “vaakaruode@gmail.com”
    • Generating public/private rsa key pair.
    • Do not overwrite main id:
      • Enter file in which to save the key (/c/Users/talon/.ssh/id_rsa): C:\Users\talon.ssh\id_rsa_vaaka
      • id_rsa files were created
      • go to another GitHub account and copy id_rsa_vaaka.pub content to SSH keys.
  • Now add the second SSH key into the SSH-Agent with:
    • $ ssh-add id_rsa_vaaka
    • Identity added
  • Create SSH config file:

config file in .ssh folder describes what accounts are used. Use host names in remote posts.

# Default Account (talonendm)
Host github-talonendm
   HostName github.com
   User git
   IdentityFile ~/.ssh/id_rsa

# Other account (vaakaruode)
Host github-vaakaruode
   HostName github.com
   User git
   IdentityFile ~/.ssh/id_rsa_vaaka

So, public keys added to GitHub and private keys used locally - mapped from config file.

$ git clone git@github.com:vaakaruode/vaakaruode.github.io.git
$ yes

changes to repository and push back to GitHub.


# NOT WORKING
git add .
git commit -m "change md with vaakaruode account"
git push origin main

# REMOVE COMMIT
git remote remove origin

# SETUP
git config user.name "vaakaruode"
git config user.email "vaakaruode@gmail.com"

# REMOTE ADD at vaakaruode-git folder:
git remote add origin git@github-vaakaruode:vaakaruode/vaakaruode.github.io.git
git add .
git commit -m "change md with vaakaruode account test 2"
git push origin main

clone gh-pages for main-account as

$ git clone git@github.com:talonendm/onnenpyora.git
$ cd onnenpyora
$ git checkout gh-pages 

copied materials. to vaakaruode.github.io

# REMOTE ADD at vaakaruode-git folder:

# git remote add origin git@github-vaakaruode:vaakaruode/vaakaruode.github.io.git
git add .
git commit -m "worked as before"
git push origin main

Windows credential manager - challenge

16.7.2022 struggling with git credentials, see video how to delete stored git passwords.

~/vaakaruode-git/laser (gh-pages)
$ git push
ERROR: Permission to vaakaruode/laser.git denied to talonendm.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Finally push worked for R repo (vaakaruode) as:


git push https://vaakaruode@github.com/vaakaruode/laser.git --all

git push https://vaakaruode@github.com/vaakaruode/R.git --all

NOTE - this is not more working:

	  $ git push https://vaakaruode:<password>@github.com/vaakaruode/R.git --all

tested this. remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead. remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information. fatal: Authentication failed for ‘https://github.com/vaakaruode/R.git/’

and if working with talonendm


git push https://talonendm@github.com/talonendm/talonendm.github.io.git/ --all

This is a bit slow way, especially if working simultaneously with multiple accounts. In .ssh two users are defined as

  • github-talonendm for talonendm
  • github-vaakaruode for vaakaruode

git add .
git commit -m "worked as before"
git push git@github-talonendm:talonendm/talonendm.github.io.git

git add .
git commit -m "worked as before"
git push git@github-vaakaruode:vaakaruode/R.git

Git history

If you have huge list of commits and there is a need to clear history (see heiswayi gist), do the following:


# Check out to a temporary branch:
git checkout --orphan TEMP_BRANCH

# Add all the files:
git add -A

# Commit the changes:
git commit -am "Initial commit"

# Delete the old branch:
git branch -D master

# Rename the temporary branch to master:
git branch -m master

# Finally, force update to our repository:
# git push -f origin master # original, but if ssh used e.g. for my blog I can use:
git push -f git@github-talonendm:talonendm/talonendm.github.io.git master

And similarly for gh-pages as


# Check out to a temporary branch:
git checkout --orphan TEMP_BRANCH

# Add all the files:
git add -A

# Commit the changes:
git commit -am "Initial commit"

# Delete the old branch:
git branch -D gh-pages

# Rename the temporary branch to master:
git branch -m gh-pages

# Finally, force update to our repository:
# orig: git push -f origin gh-pages
# --- git@github-talonendm:talonendm/ballrotation.git
git push -f git@github-talonendm:talonendm/ballrotation.git gh-pages


Git merge

v240708 - mess


# Add the original repository as a remote named 'daattali'
git remote add daattali https://github.com/daattali/beautiful-jekyll.git

# Fetch the latest changes from the original repository
git fetch daattali

# Rebase your branch on top of the latest 'master' from the original repository
git rebase daattali/master

# Alternatively, if you choose to merge instead of rebase
# git merge daattali/master

# Push your updated branch to your remote repository
git push origin your-branch-name



After resolving conflicts and continuing the rebase or completing the merge, you can push the updated branch to your remote repository.

Tags: git git tips
Share: Twitter