# Git + Git Hub Guide#01

Branches, Processes, Cheat Sheet, and Useful Commands

### Summary

1.  Git Branches
2.  Git Process
3.  Git Commands
4.  Git SSH Setup
5.  Git LFS
6.  Git Tips
7.  Commit Messages
8.  Git File Config .gitconfig
9.  Octokit a GitHub API Tool
10.  GitHub Pull Request
11.  GitHub Issue
12.  GitHub CLI
13.  GitHub Hub
14.  References

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662834279806/PWMYNj0dT.jpeg)

### 1\. Git Branches

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662834281609/FWhQ9kirx.png)

### 2.Git Process

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662834282923/OAHG3cr9C.png)

### 3\. Git Commands

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662834284353/m6DmJMNtt.png)

### 4\. Git SSH Setup

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662834285830/ToX8Iy92E.png)

### 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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662834287102/P4GunDrSB.png)

### 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**

![Optimize your repository using Git GC | by Ameet Prajapati | codeburst](https://cdn.hashnode.com/res/hashnode/image/upload/v1662834288476/C3ITpa_jo2.png)

Git Garbage Collector

git gc // Garbage Collector

#### e) Git Rebase

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662834289838/6rXdWlmwT.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662834291139/-huU1n8C-.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662834292425/Clh2EWWKn.png)

#### f) Git Merge

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662834293682/jX-15AeN4.jpeg)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662834294986/BzdiiuU2v.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662834296281/8hqkMe9P6.jpeg)

#### 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/")[](https://rtyley.github.io/bfg-repo-cleaner/)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662834297645/dbmeUdZuz.png)

### written in Scala

[View project onGitHub](https://github.com/rtyley/bfg-repo-cleaner)

```
$ 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](https://rtyley.github.io/bfg-repo-cleaner/#speed) : **10–720x** faster
*   [Simpler](https://rtyley.github.io/bfg-repo-cleaner/#examples) : 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](https://git-scm.com/docs/gitglossary.html#def_bare_repository) 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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662834299135/sRce2XNyrx.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662834300578/68d6sWmjx.png)

### 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")[](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")[](https://www.pluralsight.com/guides/open-a-pull-request-via-the-github-api)

### 10\. GitHub Pull Request

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662834302101/Umklq9mah.png)

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")[](https://github.com/Software-Engineering-2030/github-pull-request-script)

### 11\. GitHub Issue

### 12\. GitHub CLI

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662834303425/8EiWpN7Jv.png)

gh cli

[**GitHub CLI**  
*Take GitHub to the command line*cli.github.com](https://cli.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

*   [gh browse](https://cli.github.com/manual/gh_browse)
*   [gh codespace](https://cli.github.com/manual/gh_codespace)
*   [gh gist](https://cli.github.com/manual/gh_gist)
*   [gh issue](https://cli.github.com/manual/gh_issue)
*   [gh pr](https://cli.github.com/manual/gh_pr)
*   [gh release](https://cli.github.com/manual/gh_release)
*   [gh repo](https://cli.github.com/manual/gh_repo)

### Actions commands

*   [gh run](https://cli.github.com/manual/gh_run)
*   [gh workflow](https://cli.github.com/manual/gh_workflow)

### Additional commands

*   [gh alias](https://cli.github.com/manual/gh_alias)
*   [gh api](https://cli.github.com/manual/gh_api)
*   [gh auth](https://cli.github.com/manual/gh_auth)
*   [gh completion](https://cli.github.com/manual/gh_completion)
*   [gh config](https://cli.github.com/manual/gh_config)
*   [gh extension](https://cli.github.com/manual/gh_extension)
*   [gh gpg-key](https://cli.github.com/manual/gh_gpg-key)
*   [gh secret](https://cli.github.com/manual/gh_secret)
*   [gh ssh-key](https://cli.github.com/manual/gh_ssh-key)

### Options

`--version`Show gh version

### Examples

`$ gh issue create $ gh repo clone cli/cli $ gh pr checkout 321`

### 13\. GitHub Hub

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662834304878/BDZDrfjvq.png)

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)

### References

*   [https://git-lfs.github.com/](https://git-lfs.github.com/)
*   [https://git-scm.com/](https://git-scm.com/)
*   [https://git-scm.com/book/en/v2](https://git-scm.com/book/en/v2)
*   [https://github.com/octokit](https://github.com/octokit)
