Git + Git Hub Guide#01

Branches, Processes, Cheat Sheet, and Useful Commands
Summary
- Git Branches
- Git Process
- Git Commands
- Git SSH Setup
- Git LFS
- Git Tips
- Commit Messages
- Git File Config .gitconfig
- Octokit a GitHub API Tool
- GitHub Pull Request
- GitHub Issue
- GitHub CLI
- GitHub Hub
- References

1. Git Branches

2.Git Process

3. Git Commands

4. Git SSH Setup

a. Ubuntu
ssh-keygen-o
❯ ssh-keygen -o
Generating public/private rsa key pair.
Enter file in which to save the key (/home/biolabs/.ssh/id_rsa):
/home/biolabs/.ssh/id_rsa already exists.
Overwrite (y/n)?
(base) biolabs in ~/.ssh took 2s
b. Windows
$ ssh-keygen -t rsa -b 4096
5. Git LFS

a. Upload Files
git lfs install
git lfs track "*.psd"
git add .gitattributes
git add file.psd
git commit -m "Add design file"
git push origin main
b. Download Files
git lfs fetch
git lfs pull
c. Setup Ubuntu
sudo apt-get install git-lfs
git lfs install
6. Git Tips
a) How to change the commit message?
git commit -m “First Commmit” // wrong commit message
git commit -m “First Commit” — ammend
b) Git Reset
- Hard
- Soft
git reset --soft HEAD~3
c) Git Pager
git config --global pager.log true
git config --global pager.log fale
d) Git Garbage Collector

Git Garbage Collector
git gc // Garbage Collector
e) Git Rebase



f) Git Merge



g) BFG Repo Cleaner
[BFG Repo-Cleaner
bfg --strip-blobs-bigger-than 100M --replace-text banned.txt repo.git The BFG is a simpler, faster alternative to…rtyley.github.io](https://rtyley.github.io/bfg-repo-cleaner/ "https://rtyley.github.io/bfg-repo-cleaner/")

written in Scala
$ bfg --strip-blobs-bigger-than 100M --replace-text banned.txt repo.git
an alternative to git-filter-branch
The BFG is a simpler, faster alternative to [git-filter-branch](https://git-scm.com/docs/git-filter-branch) for cleansing bad data out of your Git repository history:
- Removing Crazy Big Files
- Removing Passwords, Credentials & other Private data
The git-filter-branch command is enormously powerful and can do things that the BFG can't - but the BFG is much better for the tasks above, because:
- Faster : 10–720x faster
- Simpler : The BFG isn’t particularily clever, but is focused on making the above tasks easy
- Beautiful : If you need to, you can use the beautiful Scala language to customise the BFG. Which has got to be better than Bash scripting at least some of the time.
Usage
First clone a fresh copy of your repo, using the [--mirror](https://stackoverflow.com/q/3959924/438886) flag:
$ git clone --mirror git://example.com/some-big-repo.git
This is a bare repo, which means your normal files won’t be visible, but it is a full copy of the Git database of your repository, and at this point you should make a backup of it to ensure you don’t lose anything.
Now you can run the BFG to clean your repository up:
$ java -jar [bfg.jar](https://repo1.maven.org/maven2/com/madgag/bfg/1.14.0/bfg-1.14.0.jar) --strip-blobs-bigger-than 100M some-big-repo.git
The BFG will update your commits and all branches and tags so they are clean, but it doesn’t physically delete the unwanted stuff. Examine the repo to make sure your history has been updated, and then use the standard [git gc](https://git-scm.com/docs/git-gc) command to strip out the unwanted dirty data, which Git will now recognise as surplus to requirements:
$ cd some-big-repo.git
$ git reflog expire --expire=now --all && git gc --prune=now --aggressive
Finally, once you’re happy with the updated state of your repo, push it back up (note that because your clone command used the *--mirror* flag, this push will update all refs on your remote server):
$ git push
7. Commit Messages


Example
feat: add hat wobble
^--^ ^------------^
| |
| +-> Summary in present tense.
|
+-------> Type: chore, docs, feat, fix, refactor, style, or test.
More Examples:
feat: (new feature for the user, not a new feature for build script)fix: (bug fix for the user, not a fix to a build script)docs: (changes to the documentation)style: (formatting, missing semi colons, etc; no production code change)refactor: (refactoring production code, eg. renaming a variable)test: (adding missing tests, refactoring tests; no production code change)chore: (updating grunt tasks etc; no production code change)
8. Git File Config .gitconfig
[user]
email = xx@gmail.com
name = xxx
[filter "lfs"]
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
required = true
[alias]
lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
#s = !git status -smudge
#c = !git add --all && git commit -m
#l = !git log --graph --pretty=format:'%C(blue)%h %C(blue)%d %C(white)%s - %C(cyan)%cn, %C(green)%cr
s = status -s
c = add --all && git commit -m
l = log --graph --pretty=format:'%C(blue)%h %C(red)%d %C(white)%s - %C(cyan)%cn, %C(green)%cr'
editor = config --global --edit
[core]
editor = code --wait
[init]
defaultBranch = main
[pager]
status = true
diff = false
log = false
9. Octokit a GitHub API Tool
- Official clients for the GitHub API
[Octokit
Official clients for the GitHub API The all-batteries-included GitHub SDK for Browsers, Node.js, and Deno. TypeScript…github.com](https://github.com/octokit "https://github.com/octokit")
Open a Pull Request via the GitHub API
npm install --save-dev @octokit/core
import { Octokit } from "@octokit/core";
2
3const octokit = new Octokit({ auth: 'your-token!' }),
4 owner = 'test-user',
5 repo = 'test-repo',
6 title = 'My Test Pull Request',
7 body = 'This pull request is a test!',
8 head = 'my-feature-branch',
9 base = 'develop-branch';
10
11const response = await octokit.request(
12 `POST /repos/{owner}/{repo}/pulls`, { owner, repo, title, body, head, base }
13);
[Open a Pull Request via the GitHub API
Zachary Bennett Front End Web Development When working on new features or bug fixes within your app, using the GitHub…www.pluralsight.com](https://www.pluralsight.com/guides/open-a-pull-request-via-the-github-api "https://www.pluralsight.com/guides/open-a-pull-request-via-the-github-api")
10. GitHub Pull Request

GitHub Pull Request Process
GitHub Pull Request Script
[GitHub - Software-Engineering-2030/github-pull-request-script: This script automates the process of…
This script automates the process of creating pull requests with specific changes in multiple repositories. Use the…github.com](https://github.com/Software-Engineering-2030/github-pull-request-script "https://github.com/Software-Engineering-2030/github-pull-request-script")
11. GitHub Issue
12. GitHub CLI

gh cli
[GitHub CLI
Take GitHub to the command linecli.github.com](https://cli.github.com/ "https://cli.github.com/")
Installation
conda install gh — channel conda-forge
Conda
Install:conda install gh --channel conda-forge
Upgrade:conda update gh --channel conda-forge
gh
Work seamlessly with GitHub from the command line.
Core commands
Actions commands
Additional commands
Options
--versionShow gh version
Examples
$ gh issue create $ gh repo clone cli/cli $ gh pr checkout 321
13. GitHub Hub

Hub.Githuc.com
# clone your own project
hub clone dotfiles
→ git clone git://github.com/YOUR_USER/dotfiles.git
# clone another project
hub clone github/hub
→ git clone git://github.com/github/hub.git
# fast-forward all local branches to match the latest state on the remote
cd myproject
hub sync
# list latest open issues in the current repository
hub issue --limit 10
# open the current project's issues page
hub browse -- issues
→ open https://github.com/github/hub/issues
# open another project's wiki
hub browse rbenv/ruby-build wiki
→ open https://github.com/rbenv/ruby-build/wiki
# share log output via Gist
hub gist create --copy build.log
→ (the URL of the new private gist copied to clipboard)
Starting a new project has never been easier:
# create a repo to host a new project on GitHub
git init
git add .
git commit -m "And so, it begins."
hub create
→ (creates a new GitHub repository with the name of the current directory)
git push -u origin HEAD
Lowering the barrier to contributing to open-source
Whether you are beginner or an experienced contributor to open-source, hub makes it easier to fork repositories, check the CI status of a branch, and even submit pull requests from the same environment where you write & commit your code.
hub clone octocat/Spoon-Knife
cd Spoon-Knife
# create a topic branch
git checkout -b feature
# make some changes...
git commit -am "done with feature"
# It's time to fork the repo!
hub fork --remote-name origin
→ (forking repo on GitHub...)
→ git remote add origin git@github.com:YOUR_USER/Spoon-Knife.git
# push the changes to your new remote
git push origin feature
# check the CI status for this branch
hub ci-status --verbose
# open a pull request for the branch you've just pushed
hub pull-request
→ (opens a text editor for your pull request message)




