GitHub usage via git - fordsfords/fordsfords.github.io GitHub Wiki

Setup

If necessary, do https://github.com/fordsfords/fordsfords.github.io/wiki/Things-I-forget#Shared_ssh_keys

$ mkdir ~/GitHub
$ cd ~/GitHub
$ git config --global user.name "Steve Ford"
$ git config --global user.email "[email protected]"
$ git config --global push.default simple

Now need to set up ssh connectivity between laptop and GitHub.

$ cat ~/.ssh/id_rsa.pub

Go to repo on github.com. Pull down menu under user, "Settings". On right, "SSH and GPG keys". "New SSH Key". "Work laptop". "Authentication Key". Paste in public key. "Add SSH key".

$ eval `ssh-agent`
Agent pid 21975
$ ssh-add ~/.ssh/id_rsa
Identity added: /home/sford/.ssh/id_rsa (sford)
...

Init New Repo

Create it on github.com and then clone it. (Pull down "+" at top-right next to user avatar.) Be sure to check owner and public.

Clone a repo

$ git clone [email protected]:UltraMessaging/mon_demo.git
Cloning into 'mon_demo'...
Warning: Permanently added the ECDSA host key for IP address '140.82.113.3' to the list of known hosts.
remote: Enumerating objects: 77, done.
remote: Counting objects: 100% (77/77), done.
remote: Compressing objects: 100% (55/55), done.
remote: Total 77 (delta 42), reused 54 (delta 22), pack-reused 0
Receiving objects: 100% (77/77), 93.10 KiB | 3.00 MiB/s, done.
Resolving deltas: 100% (42/42), done.
$ cd mon_demo

Read-only clone (don't need keys):

git clone https://github.com/fordsfords/cprt.git

Modify, Commit

$ vi README.md
$ git status
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   README.md

no changes added to commit (use "git add" and/or "git commit -a")
$ git add .
$ git diff --staged
diff --git a/README.md b/README.md
index c005c0d..445524c 100644
--- a/README.md
+++ b/README.md
@@ -35,7 +35,7 @@ to demonstrate setting up UM automatic monitoring.

 All of the documentation and software included in this and any
 other Informatica Ultra Messaging GitHub repository
-Copyright (C) Informatica. All rights reserved.
+Copyright (C) Informatica, 2022. All rights reserved.

 Permission is granted to licensees to use
 or alter this software for any purpose, including commercial applications,
$ git commit -m "Added copyright year"
[main d6bcf21] Added copyright year
 1 file changed, 1 insertion(+), 1 deletion(-)
$ git push
Warning: Permanently added the ECDSA host key for IP address '140.82.113.4' to the list of known hosts.
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 12 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 309 bytes | 309.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To github.com:UltraMessaging/mon_demo.git
   cbe0ba9..d6bcf21  main -> main

Add New File, Remove Old File

$ mv lbm.sh lbm.sh.example
$ vi lbm.sh.example
$ git status    # should show new file and deleted file
$ git add .

If change mind and want the old lbm.sh back, use "get restore --staged lbm.sh".

gh-pages

$ git fetch; git checkout gh-pages; git merge main; git push; git checkout main

Branches

Create new branch:

$ git checkout -b test1    # -b creates and switches to it.
Switched to branch 'test1'
$ git push -u origin test1

Fetch a branch:

$ git fetch
$ git checkout test3

Merge parallel work

Same branch (by somebody else):

$ git fetch
$ git checkout test3  # if necessary
$ git merge

Merge branches:

$ git merge test3

Undo (Cancel Changes):

https://docs.gitlab.com/ee/topics/git/numerous_undo_possibilities_in_git/ - long page. Short version: if a modified file hasn't been "staged" yet:

git checkout -- file

If it is staged but not committed:

git reset HEAD file

If it is committed (need to experiment to understand):

git revert commit-id

Mini Cheat Sheet

Create repo using web interface. Then clone.
When create repo, grant um_engineers admin
  (Settings, Collaborators and teams, Manage access)

git clone [email protected]:UltraMessaging/mon_demo.git
git clone [email protected]:fordsfords/mkbin.git

git add .
git status
git commit -m "comment"
git push

# New branch
git checkout -b mybranch
git push -u origin newbranch

# Merge
git fetch
git merge otherbranch

# Switch to existing branch
git checkout mybranch

# Diff
git diff [file]
git diff --staged [file]

# Cancel changes (pre-stage):
git checkout -- file

# Cancel changes (staged):
git reset HEAD file

# Update gh-pages (assuming it exists)
git fetch; git checkout gh-pages; git merge main; git push; git checkout main

Resources

Why?

I've been a happy user of github desktop for some time. I like the GUI.

But now I have a Windows machine. But I do all my work in WSL Ubuntu. So I tried CDing to the Windows file system and maintaining the files there. But when WSL runs on a Windows fs, the file permissions are messed up. Basically, all files appear to be 777 (octal). And when I use WSL to set file permissions the way I want them, they aren't set correctly by Windows.

As it happens, I've been irrationally embarrassed to have become so dependent on the github desktop GUI. I know it's stupid - good engineers uses the tool chain they're most efficient and effective with, so long as they aren't close-minded to new ideas. But I remember so clearly the feeling of having finally "come home" when I went from Windows to Unix, oh so many years ago. You couldn't cut-and-paste text from so many Windows GUI tools (meaning that you had to TYPE the text that was right in front of your eyes), and Windows batch files (of the day, not today's PowerShell) weren't good enough to create decent tools. Shell scripting was in my blood before I know what shell scripting was. Transitioning to Unix felt like an heavy weight was lifted from my shoulders so I could finally run free. (Think I'm exaggerating? You don't know me very well.)

But I was never a great fan of git. It is unnecessarily complex for my purposes. But the GitHub's desktop app made it simple and avoided many rooky mistakes. Less to remember.

But now it's broken, at least for my purposes. Rather than finding a usable hack (which I'm sure somebody has come up with), I think it's time for me to learn enough git to write a set of scripts to effectively create and maintain GitHub repos from the shell.

Thanks to

⚠️ **GitHub.com Fallback** ⚠️