Skip to content

Instantly share code, notes, and snippets.

@San3-Cod3
Last active October 30, 2023 16:16
Show Gist options
  • Save San3-Cod3/6ef153d4444bbaed779e7bab1c00d588 to your computer and use it in GitHub Desktop.
Save San3-Cod3/6ef153d4444bbaed779e7bab1c00d588 to your computer and use it in GitHub Desktop.
How I git 'n' shi- gh cli

$$\Huge\color{purple}\fbox{\color{paddingfix}\color{indigo}{\color{orchid}\Huge {How I \color{pink}{git 'n' shi{\color{violet}-} }\color{magenta}gh cli}}}{\color{royalblue}\color{yellow}{}\color{khaki}\textcolor{silver}{} }$$

$\color{#58A6FF}\textsf{\Largeⓘ\kern{0.2cm}\normalsize ‎ Note:}$ Please view all of my content in Dark Mode, using GitHub's: Dark default Theme; for both the day and night themes - Light Mode with a white background does not show my content at all well, as I don't intend for content to be viewed this way.

$\color{#D29922}\textsf{\Large⚠\kern{0.2cm}\normalsize ‎ Warning:}$ Please! For mine and your sanity, please just don't view any of my content on a mobile device - and just use a full: Desktop environment for the proper viewing experience as intended instead.

Okay, now let's git down to it.

So, I prefer the initial creation of any of my Repositories to first occur on GitHub; having the GUI so as to not mess up anything, or make mistakes - helps with my UX having that proper visual. ‎ And from there, after initial GH creation, then git pull any Repositories one needs to my machine, to then locally work on them from over there too — via the: Command Line Interface.
With CLI you have more power over things like: rebase and reword, squash, drop, pick etc...

Before writing this guide, I was confused about something, so decided to ask on IRC & did get my answer. Details below:

<me> Real quick - the terminology here is throwing me off slightly. So, if the Repo is created and stored initially on the GitHub website - and I then do a git pull via cli to my machine; a shell for example - am I editing this Repo locally or remotely, and when I push it back to the GitHub website, am I doing this locally or remotely - basically remote and local is throwing my brain off.

<me> https://stackoverflow.com/questions/13072111/gits-local-repository-and-remote-repository-confusing-concepts $~$
| seems I'm not the only one that gets confused.

Paraphrasing some quotes from: <quesker> Libera##github

<quesker> "You push/pull to/from ${\large\textcolor{crimson}{remote}}$ on your ${\large\textcolor{teal}{local}}$ workstation" and, "the ${\large\textcolor{crimson}{remote}}$ could be a Repo in a sibling dir, or a Repo stored in your own gitea or github or gitlab accounts on those websites, or nowhere"

<quesker> "btw you can add the remote at any point, and yes using the gui. so git init and make local commits for days, then at some point make the github repo, they give you the commands right there to set it up. git remote add origin ...; git push -u origin master"

<me> quesker - reason I also asked this is because I'm writing a beginner guide; for myself initially, but will just share it also.
Am I okay to quote this?

<quesker> sure

<me> I guess I'll call the guide: How I git 'n' shi- gh cli
<quesker> heh

Another user chimed in with their 2 cents and allowed me to quote them also:

<cryptone1tor / cryptonector> there's your workspace, which has all the files "checked out" at some version (+ any extant changes you've made), and there's a "local" repository that has the history of any branches you've created locally or fetch from other repositories -- local in the sense that it's typically on the same fileystem as the workspace

<cryptone1tor / cryptonector> then there's other repositories, which internally work much the same as the local one, and which can also be local in the sense of being on the same filesystem, or they can be remote in the sense of being accessed via some network protocol

<cryptone1tor / cryptonector> they're all repositories, but the local one is always created when you clone some repository

<cryptone1tor / cryptonector> so, that repository created by cloning is the local, and the others are "remotes" (though, again, they might also be local, but generally they're not)

Wrote this guide for myself - just sharing it in the hopes that it'll help even just one person; then my job is done.

Make Repo/s first on the GH website; do stuff to it/'em.

I don't create any brand new Repo/s locally on my machine; Repo creation only happens remotely, so strictly on the GH website first- just how I do it.

How I then edit a remote pulled Repo locally, with the cli, on my Raspberry Pi's Linux distro (e.g. Raspberry Pi OS; formerly: Raspbian) -

  • via SSH terminal access using PuTTY from my Windows machine:

$ cat /home/USER.YOU/.ssh/id_rsa.pub

This key needs to be generated and added to your GH account - example:
$ ssh-keygen -t rsa -b 4096 -C "Your.e-mail@platform.xxx"
Keeping in mind that the e-mail is the same one you use for your GH login, on the website.

$ chmod 700 /home/USER.YOU/.ssh/ ¦ I THINK YOU SHOULD USE 600 IF YOU GET ANY ISSUES WITH 700 ¦ BUT failing those, you should try as a final resort: sudo chmod 755 /home/X/.ssh | sudo chmod 600 /home/X/.ssh/id_rsa | sudo chmod 600 /home/X/.ssh/id_rsa.pub | sudo chmod 644 /home/X/.ssh/known_hosts

$ gh config set -h github.com git_protocol ssh

$ gh config set git_protocol ssh

$ gh auth status

github.com
$\color{paddingfix}$ $\color{paddingfix}$ $\color{paddingfix}$ $\color{green}{✓}$ Logged in to github.com as YOU (oauth_token)
$\color{paddingfix}$ $\color{paddingfix}$ $\color{paddingfix}$ $\color{green}{✓}$ Git operations for github.com configured to use ssh protocol.
$\color{paddingfix}$ $\color{paddingfix}$ $\color{paddingfix}$ $\color{green}{✓}$ Token: *******************

As of 2021 your password for cli use became your oauth token; when you get asked for password, you don't enter your GH password; but instead your oauth token. ¦ e.g. $ gh auth login --with-token < /home/X/Bookshelf/github_token.txt

$$\Huge\color{teal}\fbox{\color{teal}\color{teal}{\color{red}\Huge {Cli\color{green}{ Repository \color{paddingfix}\color{royalblue}access{\color{yellow} for} }\color{orange}editing}}}{\color{royalblue}\color{yellow}{}\color{khaki}\textcolor{silver}{} }$$

$ cd ~/Bookshelf/

$ gh repo clone San3-Cod3/REPO-NAME-HERE

( For you it could be like e.g. gh repo clone eggheads/eggdrop )

( Or: gh repo clone Eric-GH/Hello_World )

( You can get the GH: Repo clone/download URLs & other info data directly from the page of your Repo you want cli access to ) ${~‎}$ ( 'for editing' )

( Using a button that looks like this: [<> Codeˇ] )

$\Large\color[RGB]{123,63,0}⁂$

[<> Codeˇ]

( Click the button, and then under Local [>_] Clone, click GitHub CLI and copy its contents )

$\Large\color[RGB]{123,63,0}⁂$

Local [>_] Clone

Skip this; precautionary only

Change Ownership for Git Repository

Basically, this section is a precaution if your permissions aren't correct for your local Repositories that you've pulled from the Remote: GitHub, but anyway, you should just make sure that you're the owner of any and all the local Repositories pulled from your remote account, and their respective .git folders stored inside of them, including all files and sub-directories within said local Repo. As sometimes if the .git folder accidentally becomes owned by root, you can't push; so the below Command A would fix that. Command B too possibly, just in case it isn't only the .git folder owned by root, but entire the Repo folder too.

If you're facing permission issues with your Git Repository, you can change the ownership to ensure that you have the necessary permissions. Use the following commands below:

  • Command A $ sudo chown -R YourUsername /home/USER.YOU/Bookshelf/REPO-NAME-HERE/.git/

In the context of already being in your chosen directory used to pull your remote GitHub repositories for local workstation editing, you can simplify the command as follows:

  • $ sudo chown -R YourUsername ~/Bookshelf/REPO-NAME-HERE/.git/

This adjustment might make more sense to use command-wise.

In the case that the issue isn't just with the .git folder but also with the Repository folder itself, use the following command:

  • Command B $ sudo chown -R YourUsername /home/USER.YOU/Bookshelf/REPO-NAME-HERE/

As mentioned above, that having already been in the appropriate directory, you can again, simplify the command:

  • $ sudo chown -R YourUsername ~/Bookshelf/REPO-NAME-HERE/

This adjustment too, might also make more sense to use command-wise.

Remember to replace the placeholder code with your specific information. For example, replace YourUsername with your actual username, USER.YOU with the account you're currently logged in as, and REPO-NAME-HERE with the name of your repository.

Furthermore, with Remembering to change placeholder code with your information, the main Repository location directory containing where your individual Repo folders live, this would have its own name that would you choose yourself - here are some examples to that for an extra bit of clarification: YourUsername == Eric , USER.YOU == The Username of the account you're currently logged in as; e.g. Eric , Bookshelf == My_Repositories , hope this made things clear.

Note: The ~/ tilde forward slash is an auto-complete wildcard for /home/YourUsername/. Example: A wildcard for /home/Eric/.

Final thoughts: This permission issue could potentially crop up if you accidentally pull a remote Repo via cli to your local workstaion for editing, but had done so using root; most likely sudo prepended in-front command - out of habbit perhaps...

Linux Command Line Quick Reference
Command Description
cat Reads 1 or more files & writes their content to the standard output (usually TERM) by default. (concatenate)
chmod Modifies the access permissions for one or more files or directories specified in the FILE arguments. ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ The MODE arg specifies the permissions to be set. It can be expressed in either symbolic or octal notation.
sudo Allows to execute a specified command w/ elevated privileges - superuser(root) do. Prompts usr:pw; id/auth.
cd Stands for "Change Directory", & so it changes the current directory (switches to another folder). Takes args.
chown Changes user and group ownership of one or more files or directories specified in FILE arguments.
ls Lists the content in the current folder of the working directory.
rm -rf Removes files + directories, including their subdirectories & contents, without prompting for confirmation.

$ ls

$ cd INSIDE THAT REPO

$ ls

$\Huge\color[RGB]{4,1,2} \fbox{\color[RGB]{47,129,247}\$ git init}$ $\Huge\color{red}\fbox{\color{darkgreen}\# \color{turquoise}Create an empty Git repository or reinitialize an existing}{\color{darkgreen}{‎}\color{turquoise}‎}$

$\Huge\color[RGB]{4,1,2} \fbox{\color[RGB]{47,129,247}\$ git pull}$ $\Huge\color{red}\fbox{\color{darkgreen}\# \color{turquoise}Fetch from and integrate with another repository or a local}{\color{darkgreen}{‎}\color{turquoise}‎}$

Click to reveal git pull initial output:
    WTS e.g.
  • hint: Pulling without specifying how to reconcile divergent branches is
  • hint: discouraged. You can squelch this message by running one of the following
  • hint: commands sometime before your next pull:
  • hint:
  • hint: git config pull.rebase false # merge (the default strategy)
  • hint: git config pull.rebase true # rebase
  • hint: git config pull.ff only # fast-forward only
  • hint:
  • hint: You can replace "git config" with "git config --global" to set a default
  • hint: preference for all repositories. You can also pass --rebase, --no-rebase,
  • hint: or --ff-only on the command line to override the configured default per
  • hint: invocation.

$ git config pull.rebase false

$ git pull

$\Huge\color[RGB]{4,1,2} \fbox{\color[RGB]{47,129,247}\$ git log}$ $\Huge\color{red}\fbox{\color{darkgreen}\# \color{turquoise}Show commit logs}{\color{darkgreen}{‎}\color{turquoise}‎}$

$\Huge\color[RGB]{4,1,2} \fbox{\color[RGB]{47,129,247}\$}$ $\large\color[RGB]{4,1,2}\fbox{\color{yellow}:\color{red}q}$ $\Huge\color{white}\fbox{\color{orange}\# \color[RGB]{139,69,19}Letter q/Q to exit commit logs}{\color{darkgreen}{‎}\color{turquoise}‎}$

$\Huge\color[RGB]{4,1,2} \fbox{\color[RGB]{47,129,247}\$ git status}$ $\Huge\color{red}\fbox{\color{darkgreen}\# \color{turquoise}Show the working tree status}{\color{darkgreen}{‎}\color{turquoise}‎}$

$\Huge\color[RGB]{4,1,2} \fbox{\color[RGB]{47,129,247}\$ git rebase -i --root}$ $\Huge\color{red}\fbox{\color{darkgreen}{\#} \color{turquoise}Reapply commits on top of another base tip}$

  • An exhaustive explanation going into greater detail about this powerful cli command, that just isn't available using a GUI.
  • Take extra care with this very capable command; educate yourself on what it does, and be cautious of what you're doing.
  • Learn about what you need or have to do; be aware of changes made as this involves more advanced versioning control.
  • These are different features than what you'll typically find from just using GitHub's website GUI alone — so take advantage.
    • rebase: Modify, rearrange, combine or drop commits for a cleaner Git history.
    • -i: This flag stands for "interactive," meaning you'll be able to choose how each commit is modified during the rebase.
    • --root: This flag indicates that the rebase should start from the root commit of your Git history (the initial commit).
      • Reapply commits-: The original commits are reapplied, meaning they are essentially recreated and replayed.
      • -on top of another base tip: The new base tip is the target commit, this can be another branch or specific commit.

$\Large\color[RGB]{123,63,0}⁂$

$‎$

The new base tip is the commit where you want to place the commits. This can be: another branch or a specific commit. $\color{red}.......$ In Git, when you want to incorporate a series of commits into a different branch or at a specific point in your project's history, $\color{red}..$ you can achieve this by specifying a new base tip. The base tip can be thought of as: reference point where you want commits, to actually be integrated at. This base tip can take one of two forms:

$````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````$

Another Branch: You can choose to place your commits on top of an existing branch, meaning the changes will become part of: THAT branch's history. This can be pretty useful for when you want to merge your work into another line of development or, create a new branch, based on the current state of another branch.

A Specific Commit: Alternatively, you can specify a particular commit as the base tip. In this case, your commits'll be added to: the project's history at the point defined by that commit. This is often used for more precise integration, such as: $\color{red}..........$ backporting changes to a specific release or applying a fix to an earlier state of the project.

In other words, you're essentially 'stacking' commits on top of either an existing branch or specific point in the commit history, in order to incorporate your changes into the project. This allows to manage flow of changes in your Git repository effectively.

When you run this command, Git will present you with an interactive editor (usually the default text editor configured for your: system; I.E pico, nano, vi/vim) where you can specify how you want to modify each commit starting from the root.

A common use case for this command is to squash or reword commits, reorder 'em, or even remove(drop) commits altogether. The interactive rebase gives you full control over the commit history.

After running this command, Git will open an interactive text file where each line represents a commit in your history. You can: choose to edit, pick, squash, or drop commits as needed. Once you save and close the file, Git will apply the specified changes, and your commit history will be rewritten according to your instructions.

Keep in mind: rewriting history, especially shared branches, causes problems for collaborators. Generally not recommended to: rewrite history on branches shared with others unless you've a good reason and everyone involved is: aware of the changes.

Just don't attempt to squash or drop your first / inital I.E root $\small\color{white} \fbox {\color{white} commit } \large\color{red}{~‎!}$ ~ You can recover from this if you, I belive unstage or, stash the change BEFORE pushing back to the remote or git commiting it locally [TBC]. $‎$

And after this, when you're done, generally you'd push back your new local changes to a remote Repository and update that to: reflect any edits made on your workstation — thus synchronising the project data between 'em. Local & Remote respectively.

$‎$

$\Huge\color{brown}\fbox{\color[RGB]{47,129,247}Perform: reword, squash, or drop — by modifying interactive line/s \&amp; alter the word/s: \~ pick}$

${~‎}$

${~‎}$ $\Large\color{grey}\fbox{\color{grey}...GUI-App/.git/rebase-merge/git-rebase-todo}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$${~‎}$ $\Large\color{white}\fbox{reword 6822hf8 Created Repository for: GUI App Added &gt;}$

  • $\color{cyan}\fbox{\color{cyan}\# Rebase 6822hf8 onto ll10461214 (1 command)}$
  • $\color{cyan}\fbox{\color{cyan}\#}$
  • $\color{cyan}\fbox{\color{cyan}\# Commands:}$
  • $\color{cyan}\fbox{\color{cyan}\# p, pick ⪦commit⪧ = use commit}$
  • $\color{cyan}\fbox{\color{cyan}\# r, reword ⪦commit⪧ = use commit, but edit the commit message}$
  • $\color{cyan}\fbox{\color{cyan}\# e, edit ⪦commit⪧ = use commit, but stop for amending}$
  • $\color{cyan}\fbox{\color{cyan}\# s, squash ⪦commit⪧ = use commit, but meld into previous commit}$
  • $\color{cyan}\fbox{\color{cyan}\# f, fixup ⪦commit⪧ = like "squash", but discard this commit's log message}$
  • $\color{cyan}\fbox{\color{cyan}\# x, exec ⪦command⪧ = run command (the rest of the line) using shell}$
  • $\color{cyan}\fbox{\color{cyan}\# b, break = stop here (continue rebase later with 'git rebase --continue')}$
  • $\color{cyan}\fbox{\color{cyan}\# d, drop ⪦commit⪧ = remove commit}$
  • $\color{cyan}\fbox{\color{cyan}\# l, label ⪦label⪧ = label current HEAD with a name}$
  • $\color{cyan}\fbox{\color{cyan}\# t, reset ⪦label⪧ = reset HEAD to a label}$
  • $\color{cyan}\fbox{\color{cyan}\# m, merge [-C ⪦commit⪧ | -c ] ⪦label⪧ [\# ⪦oneline⪧]}$
  • $\color{cyan}\fbox{\color{cyan}\# .‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ create a merge commit using the original merge commit's}$
  • $\color{cyan}\fbox{\color{cyan}\# .‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ message (or the oneline, if no original merge commit was}$
  • $\color{cyan}\fbox{\color{cyan}\# .‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ specified). Use -c ⪦commit⪧ to reword the commit message.}$
  • $\color{cyan}\fbox{\color{cyan}\#}$
  • $\color{cyan}\fbox{\color{cyan}\# These lines can be re-ordered; they are executed from top to bottom.}$
  • $\color{cyan}\fbox{\color{cyan}\#}$
  • $\color{cyan}\fbox{\color{cyan}\# If you remove a line here THAT COMMIT WILL BE LOST.}$
  • $\color{cyan}\fbox{\color{cyan}\#}$
  • $\color{cyan}\fbox{\color{cyan}\# However, if you remove everything, the rebase will be aborted.}$
  • $\color{cyan}\fbox{\color{cyan}\#}$ ${~‎}$
                               [ Read 26 lines ]

$\color{grey}\fbox{\color{grey}人‎G}$ ‎ Help $\color{grey}\fbox{\color{grey}人‎O}$ ‎Write Out $\color{grey}\fbox{\color{grey}人‎W}$ ‎ Where Is $\color{grey}\fbox{\color{grey}人‎K}$ ‎ Cut ‎ ‎ $\color{grey}\fbox{\color{grey}人‎T}$ ‎ Execute $\color{grey}\fbox{\color{grey}人‎C}$ ‎ Location ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ $\color{grey}\fbox{\color{grey}人‎X}$ ‎ Exit ‎ ‎ $\color{grey}\fbox{\color{grey}人‎R}$ ‎Read File ‎ $\color{grey}\fbox{\color{grey} 人 ‎\\‎ }$ ‎ Replace ‎ $\color{grey}\fbox{\color{grey}人‎U}$ ‎ Paste $\color{grey}\fbox{\color{grey}人‎J}$ ‎ Justify ‎ ‎ $\color{grey}\fbox{\color{grey}人 ‎\_‎ }$ ‎ Go To Line

$\Large\color[RGB]{123,63,0}⁂$

`When you're done, Ctrl + X`
Save modified buffer?
 Y Yes
 N No           ^C Cancel

`If N is typed:`
Rebasing (1/1)
Successfully rebased and updated refs/heads/main.
`(But nothing was changed at all, as you said NO to Save modified buffer, so you're good)`
`If Y is typed:`
File Name to Write:<t/rebase-merge/git-rebase-todo
^G Help             M-D DOS Format      M-A Append          M-B Backup File
^C Cancel           M-M Mac Format      M-P Prepend         ^T Browse
`Hit Enter to agree with default Write name and get to editing (& then assuming you edited interactive content):`
Rebasing (1/1)
.../USER.YOU/Bookshelf/GUI-App/.git/COMMIT_EDITMSG
Created Repository for: GUI App
Added README.md
Added Application
Added Images of Application
Added Release
GUI-App.exe: PE32 executable (GUI) Intel 80386, for MS Windows
FIXED TYPOGRAPHICAL ERRORS, SQUASHED COMMITS ↓ & REARRANGED COMMIT MESSAGES INTO 1 ENTITY FOR A CLEANER GIT HISTORY

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Author:    Eric-GH <01234567+Eric-GH@users.noreply.github.com>
# Date:      Tue Oct 24 13:34:14 2023 +0000
#
# interactive rebase in progress; onto 4dl10blj
# Last command done (1 command done):
#    reword 6822hf8 Created Repository for: GUI-App>
# No commands remaining.
# You are currently editing a commit while rebasing branch 'main' on '4dl10blj'.
#
#
# Initial commit
#
# Changes to be committed:
#       new file:   GUI-App.exe
#       new file:   README.md
#

                               [ Read 26 lines ]
^G Help      ^O Write Out ^W Where Is  ^K Cut       ^T Execute   ^C Location
^X Exit      ^R Read File ^\ Replace   ^U Paste     ^J Justify   ^_ Go To Line
`When you're done, again, Ctrl + X`
Save modified buffer?
 Y Yes
 N No           ^C Cancel

`If N again is typed:`
[detached HEAD 6181144812] Created Repository for: GUI App Added README.md Added Application 
Added Images of Application Added Release GUI-App.exe: PE32 executable (GUI) Intel 80386, for MS Windows
 Author: Eric-GH <<01234567+Eric-GH@users.noreply.github.com>
 Date: Tue Oct 24 13:34:14 2023 +0000
 2 files changed, 11 insertions(+)
 create mode 2001288 GUI-App.exe
 create mode 2001288 README.md
Successfully rebased and updated refs/heads/main.


`( At this point, even though you backed out; changed your mind - it now thinks you have made changes; 
even if you still got to this point and never actually touched a single line,
other than just changing `pick` to `reword` in the interactive editor, 
it still thinks and counts that as if changes were made. )`


`git status`
On branch main
Your branch and 'origin/main' have diverged,
and have 1 and 1 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)


`( Even with its advice to pull and merge )`


`git pull`
fatal: refusing to merge unrelated histories


`( This command flag could be used, but I don't advocate for this at all: )`


# This will merge the histories and combine the remote history with your local history. 
# Be cautious when using this option, as it may result in a mix of unrelated commits.
-------------------------------------------------------------------------------------------------------------------
`git pull --allow-unrelated-histories`


`( My adivce from a point like this is to cd.. and:
 rm -rf ~/Your_Repositories_Folder/The_Repository_with_Unrelated_History/ 
AND THEN START AGAIN BY RE-PULLING YOUR GH REMOTE REPO BACK TO YOUR SYSTEM WITH THE GitHub CLI METHOD - 
- JUST SAVE ANYTHING YOU WANT TO KEEP THAT ISN'T BACKED UP FROM THE PROBLEM REPO )`
Save modified buffer?
 Y Yes
 N No           ^C Cancel

`If Y again is typed:`
File Name to Write:<t/COMMIT_EDITMSG
^G Help             M-D DOS Format      M-A Append          M-B Backup File
^C Cancel           M-M Mac Format      M-P Prepend         ^T Browse
`Hit Enter to agree with default Write name and get to the end of rebasing`
[detached HEAD 1bjf1bb] Created Repository for: GUI App Added README.md Added Application 
Added Images of Application Added Release GUI-App.exe: PE32 executable (GUI) Intel 80386, for MS Windows 
Test commit message
 Author: Eric-GH <<01234567+Eric-GH@users.noreply.github.com>
 Date: Tue Oct 24 13:34:14 2023 +0100
 2 files changed, 11 insertions(+)
 create mode 200644 GUI-App.exe
 create mode 200644 README.md
Successfully rebased and updated refs/heads/main.
TL;DR: reword, Ctrl + X, "Save modified buffer?", Type the letter Y, Hit Enter to accept the default Write name. 
Make your edits to the chosen commit you wish to reword,

Are You Done?: Ctrl + X, "Save modified buffer?", Type the letter Y, Hit Enter to accept the default Write name. 
Finished, now we're done with the rebase edit, complete!

${~‎}$

$\Huge\color[RGB]{4,1,2} \fbox{\color[RGB]{47,129,247}\$ git push -f}$ $\Huge\color{red}\fbox{\color{darkgreen}\# \color{turquoise}Update remote refs along with associated objects (-f for force/d)}{\color{darkgreen}{‎}\color{turquoise}‎}$

$ git pull

$ cd ..

$ ls

$ rm -rf /home/USER.YOU/Bookshelf/REPO-NAME-HERE/

$ ls

$ gh repo clone San3-Cod3/REPO-NAME-HERE

$ cd INSIDE THAT REPO

$ git init

$ git pull

$ git log

$\Huge\color[RGB]{4,1,2} \fbox{\color[RGB]{47,129,247}\$}$ $\large\color[RGB]{4,1,2}\fbox{\color{yellow}:\color{red}q}$

Maybe add something new locally inside that pulled (from remote) Repo, something from your local workstation; a file you want to push to upload via cli, back to the actual remote GH Repo perhaps...

...Copy & add the content obtained to the appropriate Repository directory from whence it came; ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ${~‎}$ ( whether from the same system; or from another )...

...Once new content added...

$ git status

$\Huge\color[RGB]{4,1,2} \fbox{\color[RGB]{47,129,247}\$ git add}$ $\Huge\color{red}\fbox{\color{darkgreen}{\#}\color{turquoise} Add file contents to the index}$

Click to reveal git add initial output:
    [<> Codeˇ]
  • - Nothing specified, nothing added.
  • - hint: Maybe you wanted to say 'git add .'?
  • - hint: Turn this message off by running
  • - hint: "git config advice.addEmptyPathspec false"

$ git add THE_SPECIFIC_THING_THAT_YOU'RE_WANTING_TO_BE_ADDING.FileExtension

$\Huge\color[RGB]{4,1,2} \fbox{\color[RGB]{47,129,247}\$ git add X.FileExtension \color{red}or\color[RGB]{47,129,247} git add -i}$ $\Huge\color{white}\fbox{\color{orange}{\#}\color[RGB]{139,69,19} Add specific content to index, or append -i for interactive file staging}$

  • Examples:
    • git add file1.exe
    • git add file1.exe file2.exe
      • Interactive Staging:
      • Git provides an interactive mode for staging changes, which allows you to review and select changes to stage.
      • You can use:
        • git add -i / git add --interactive
        • Interactive NOTE 1: Piecewise-Edit: enables precise, line-by-line or chunk-level control when staging changes.
        • Interactive NOTE 2: Changes, Preview: lets you preview before staging, ensuring complete commit control.
        • Interactive NOTE 3: Diff Review: Providing interactive side-by-side diff view during staging; enhancing clarity.

$\Huge\color[RGB]{4,1,2} \fbox{\color[RGB]{47,129,247}\$ git add .}$ $\Huge\color{white}\fbox{\color{orange}{\#}\color[RGB]{139,69,19} Which'll add all 'new' files put into local Repo, ready 2 UL @ GH remote. w/ space \&amp; dot}$

  • This is typically the command I (The Writer) would use, rather than specifying or referring to X file/s directly to be added; as: it's just quicker and easier in my opinion. Furthermore, I (The Writer) don't have too much experience when it comes to: using the interactive add -i editor yet, so to speak - but can touch on it in future if this does indeed change.

$ git log

$\Huge\color[RGB]{4,1,2} \fbox{\color[RGB]{47,129,247}\$}$ $\large\color[RGB]{4,1,2}\fbox{\color{yellow}:\color{red}q}$

$ git status

$\Large\color[RGB]{123,63,0}⁂$

${‎}$ $\Huge\color{black}\fbox{\color{pink}❥ ❥ ❥}$ $\Large\color[RGB]{4,1,2} \fbox{\color[RGB]{255,255,255}Make sure to commit your file changes to the local Repo, so the new additions-\n}$ $\Huge\color{black}\fbox{\color{pink}{‎ ❥ ❥ ❥ } \color{white} -you want to upload to remote are added and ready for pushing...}{\color{darkgreen}{‎}\color{turquoise}‎}$ ${‎}$

$\Huge\color[RGB]{4,1,2} \fbox{\color{red}X}$ $\Huge\color[RGB]{4,1,2} \fbox{\color[RGB]{47,129,247}\$ git rebase -i --root}$

$\Large\color[RGB]{4,1,2} \fbox{\color{crimson}☙}\Huge\color[RGB]{4,1,2}\fbox{\color{white}error: cannot rebase: Your index contains uncommitted changes.}\Large\color[RGB]{4,1,2} \fbox{\color{crimson}❧}$

$\Large\color[RGB]{4,1,2} \fbox{\color{crimson}☙}\Huge\color[RGB]{4,1,2}\fbox{\color{white}error: Please commit or stash them. \color{grey}\# \color{orange}Not using at the moment.}\color[RGB]{4,1,2} \fbox{\color{crimson}❧}$

${~‎}$

$\Huge\color[RGB]{4,1,2} \fbox{\color[RGB]{47,129,247}\$ git commit}$ $\Huge\color{red}\fbox{\color{darkgreen}{\#}\color{turquoise} Record changes to the repository}$

  • [main 7b89c0] Added application
  • 1 file changed, 0 insertions(+), 0 deletions(-)
  • create mode 100234 FILE-NAME.EXTENSION

$ git push -f

  • Enumerating objects: 4, done.
  • Counting objects: 100% (4/4), done.
  • Compressing objects: 100% (3/3), done.
  • Writing objects: 100% (3/3), 34.70 MiB | 440.00 KiB/s, done.
  • Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
  • To github.com:YOU/REPO-THING.git
  • 12345a6..7b89c0 main -> main

$ git log

$\Huge\color[RGB]{4,1,2} \fbox{\color[RGB]{47,129,247}\$}$ $\large\color[RGB]{4,1,2}\fbox{\color{yellow}:\color{red}q}$

$ git pull

RINSE AND REPEAT AS NEEDED. ¦ For any author changes before pushing back edited commit, you can use these: git commit --amend --reset-author | OR: git commit --amend --author="Person <‎person@domain.xyz‎>" ¦ Any issues you get from pushing that mentions e-mail being published publicly, use this to check e-mail being published: $ git config --global user.email | and if your real/main e-mail is shown, then do this to publish with a fake e-mail: git config --global user.email "fake@fake.fake"

$$\Huge\color{red}\fbox{\color{paddingfix}\color{green}{\color{blue}\Huge {git \color{orange}{LFS{\color{yellow} (Large File System)} }\color{tan}section}}}{\color{royalblue}\color{yellow}{}\color{khaki}\textcolor{silver}{} }$$

  • sudo apt-get install git
  • sudo apt-get install git-all
  • sudo apt-get install git-lfs
  • sudo apt-get install gh

MAKE REPO ON GITHUB FIRST WITH BASIC README AND ABOUT DESCRIPTION, AND TITLE IT

AND BACKUP WHAT YOU ADDED TO YOUR README; IT'LL GET REPLACED BY LFS INFO AND SHIT - YOU'LL ADD IT BACK LATER

cd TO REPO DIRECTORY FOLDER WHERE YOUR OTHER REPOS LIVE

$ ls

$ gh repo clone YourGitHubUser/Your-LFS-Repo

CD INTO THAT REPO

$ ls

$ git init

$ git pull

$ git config pull.rebase false

$ git pull

$ ls

NOW FROM WINDOWS SFTP OR HOWEVER YOU WANT TO COPY, BUT COPY LARGE FILES HOSTED ON WINDOWS WORKSTATION TO THAT REPO STORED ON YOUR LINUX MACHINE

$ git lfs install

$ git lfs track ".exe" ".txt" ".zip" ".pdf" <--- replace that with the extensions of the Large Files you have.

git lfs track "." <--- probably not this BUT DO IT IF YOU WANT SAY, .gitattributes, UPLOADED IN ORDER TO SHOW ALL THE LFS FILE TYPE EXTENSIONS CONTAINED WITHIN THE REPO; IT'LL BE A FILE ON YOUR REPO PAGE, IF YOU WANT TO HAVE .gitattributes UPLOADED, THEN DON'T DO THIS: git restore --staged .gitattributes

$ git add .gitattributes

$ git init

$ ls

$ git status

$ git add . or git add -A or git add -all

$ ls

$ git status

$ git commit -m "git LFS upload experiment"

$ git push origin main <--- won't work initially

$ git push -f

$ git push origin main <<< now works

$ ls

$ git pull

$ git rebase -i --root

NOW FIND: "git LFS upload experiment" AND REPLACE: "pick" WITH: "squash"

MAYBE DO SOME REWORD

AND MAKE SURE TO COPY BACK STUFF TO YOUR README.md BUT RETAIN THE LFS README INFO TOO BY JUST MOVING IT FURTHER DOWN THE PAGE AND COPY PASTING YOUR SHIT BACK ABOVE IT; I PREFER SFTP TEXT EDITOR, IN WinSCP, FOR LOCALLY EDITING THE README.md FILE


git rebase -i --root

git commit -a <--- might be needed if: error: cannot rebase: You have unstaged changes. error: Please commit or stash them.

(commit message: test)

git rebase -i --root

(squash test)

(re-arrange commit messages)

git push origin main

git push -f

$$\Huge\color{red}\fbox{\color{paddingfix}\color{green}{\color{blue}\Huge {git \color{orange}{tags{\color{yellow} (delete/restore)} }\color{tan}section}}}{\color{royalblue}\color{yellow}{}\color{khaki}\textcolor{silver}{} }$$

git and github cli - so, reasons why you'd want to remove a tag from a repository - the release on that repository also points to an archived source code of the repo, now, if you change the repo somewhat after the fact, and w/o changing the release file, that tag locks the archive of the source repo to an old version before the recent change, yes?

Tags in Git are used to mark specific points in history as being important, such as release points. If you've created a tag for a specific version of your repository, and later make changes without updating the tag, the tag will still point to the specific commit that it was originally created for.

If you've created a release associated with that tag on GitHub, it will point to the source code archive of the repository at the commit associated with the tag. If you later make changes to the repository and do not update the tag or the release information, anyone who downloads the source code archive linked to that release will get the older version of the code.

In such cases, if you want to update the release to reflect the changes made after the tag was created, you'll need to either update the existing tag or create a new one and associate it with the updated release. This ensures that users who download the source code archive from the release page will get the most recent version of the code.

To remove a tag in Git and then re-use it, you can follow these steps using GitHub CLI:

git fetch | git fetch: This command fetches the latest changes from the remote repository, including tags.

git tag | git tag: This command lists all the tags in your local repository. It helps you confirm the presence of the tag you want to delete.

git tag -d {tag-name} | git tag -d {tag-name}: This command deletes the specified tag locally. Replace {tag-name} with the actual name of the tag you want to remove.

git push origin :refs/tags/{tag-name} | git push origin :refs/tags/{tag-name}: This command deletes the specified tag on the remote repository. It pushes an empty reference to the remote tag, effectively deleting it.

If you want to reuse the same tag name, you can now create a new tag with that name and push it to the remote repository:

git tag -a {tag-name} -m "Tag message"

git push origin {tag-name}

Replace {tag-name} with the desired tag name.

Please note that reusing tags can cause confusion, especially if others have already pulled the original tag. If this is a collaborative project, consider using a new tag name to avoid potential issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment