Git(Hub)
Install
sudo apt-get install git
git --version git --help
usage: git [-v | --version] [-h | --help] [-C <path>] [-c <name>=<value>] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path] [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--no-lazy-fetch] [--no-optional-locks] [--no-advice] [--bare] [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>] [--config-env=<name>=<envvar>] <command> [<args>] These are common Git commands used in various situations: start a working area (see also: git help tutorial) clone Clone a repository into a new directory init Create an empty Git repository or reinitialize an existing one work on the current change (see also: git help everyday) add Add file contents to the index mv Move or rename a file, a directory, or a symlink restore Restore working tree files rm Remove files from the working tree and from the index examine the history and state (see also: git help revisions) bisect Use binary search to find the commit that introduced a bug diff Show changes between commits, commit and working tree, etc grep Print lines matching a pattern log Show commit logs show Show various types of objects status Show the working tree status grow, mark and tweak your common history backfill Download missing objects in a partial clone branch List, create, or delete branches commit Record changes to the repository merge Join two or more development histories together rebase Reapply commits on top of another base tip reset Reset current HEAD to the specified state switch Switch branches tag Create, list, delete or verify a tag object signed with GPG collaborate (see also: git help workflows) fetch Download objects and refs from another repository pull Fetch from and integrate with another repository or a local branch push Update remote refs along with associated objects 'git help -a' and 'git help -g' list available subcommands and some concept guides. See 'git help <command>' or 'git help <concept>' to read about a specific subcommand or concept. See 'git help git' for an overview of the system.
Prerequisites
## Configure User Information git config --global user.email "<email>" git config --global user.name "<username>"
## Configure User Information for Individual Repository git config --local user.email "<email>" git config --local user.name "<username>"
## Configure User Information for GitHub git config --global user.email "12345678+<username>@users.noreply.github.com" git config --global user.name "<username>"
## Config Confirmation git config list
## Unset Configuration git config --unset user.name git config --unset --global user.name
Alias
git config --global alias.st 'status' git config --global alias.br 'branch' git config --global alias.sw 'switch' git config --global alias.ci 'commit' git config --global alias.ad 'add' git config --global alias.pl 'pull' git config --global alias.ps 'push' git config --global alias.mg 'merge' git config --global alias.df 'diff' git config --global alias.lg "log --oneline --graph --decorate --branches --tags --remotes --all"
Repository
Clone Existing Repository
## Clone a specific branch git clone [-b <branch>] <repository> git clone [-b <branch>] <repository> [<directory>] git clone [-b <branch>] https://github.com/<repository>
New Repository from Remote
git clone [repository] git branch -M main git commit -m "initial commit" --allow-empty git push
New Repository from Local
git init -b main git commit -m "initial commit" --allow-empty git remote add origin [repository] git push -u origin main
Information
git status git branch git branch -a git tag git tag -l git log git show git diff
Commit
touch README.md git add README.md git commit -m "<message>" git push
Staging Area
## Check Status git status
## Stage All Files git add .
## Stage Individual File git add <file>
## Reset Staged Files git reset
Ignoring Files
touch .gitignore
Branch
## Branch Confirmation git branch git branch -a
## New Branch git branch <branch>
## Set Upstream Branch git push -u origin <branch> git branch -u origin/<branch> <branch>
## Switch Current Branch git switch <branch>
## Rename Branch git branch -m <old_branch> <new_branch>
## Remove Branch git branch -d <branch> git branch -D <branch> git push --delete origin <branch>
Merge
git switch <branch> git merge <merge_branch>
Common Development Flow
## Update Main Branch git switch main git pull
## Switch to (or Create New) Develop Branch git switch [-c] <develop_branch>
## Change Develop Branch git add . git commit -m "<message>"
## Push Results to Remote Repository (as needed) git push -u origin <develop_branch>
## Merge Develop Branch into Main Branch git switch main git pull git merge <develop_branch>
## Push Merged Results to Remote Repository git push origin main
## Remove Develop Branch git branch -d <develop_branch>
Pull Request in Public Repository
https://docs.github.com/pull-requests
## 1. Fork public repository as a private repository: github.com ## https://docs.github.com/get-started/quickstart/fork-a-repo
## 2. Clone forked repository to local machine: remote > local git clone https://github.com/[user]/[repository(forked)] cd [repository(forked)]
## 3. Generating new branch for development: local git checkout -b dev #git branch dev origin/master #git checkout dev
## 4. Update content(s) of new branch for development: local ... depending on your project ...
## 5. Adding new or changed files to Git staging area: local git add updated.sh
## 6. Saving change(s): local git commit -m "[comment]"
## 7. Updating remote repository: local > remote git push origin dev
## 8. Pull Request: github.com ## https://docs.github.com/pull-requests
Troubleshooting - Password Authentication Failure
## remote: Support for password authentication was removed on August 13, 2021.
## Login to GitHub ## Settings > Developer settings > Personal access tokens (classic) > Generate new token (classic) ## Use generated token as a password
Troubleshooting - Private Email Error
## remote: error: GH007: Your push would publish a private email address. ## remote: You can make your email public or disable this protection by visiting: ## remote: http://github.com/settings/emails
## Login to GitHub ## Settings > Emails > Block command line pushes that expose my email = Off
References
https://zenn.dev/k_tana/articles/2023-05_basic-git-learning
https://qiita.com/shimotaroo/items/ed08d76447144d566637
https://qiita.com/konweb/items/621722f67fdd8f86a017
https://qiita.com/samurai_runner/items/7442521bce2d6ac9330b
https://tech-blog.rakus.co.jp/entry/20200529/git
https://ios-docs.dev/20210813support-for-password/
https://qiita.com/setonao/items/28749762c0bc1fbbf502
https://qiita.com/atsymd/items/a1ff5a496b78f47ce80e
https://qiita.com/satoshi1335/items/ead109412430a078feaa
https://zenn.dev/kaluna_hart/articles/github-email-error
Acknowledgments
Daiphys is a professional services company in research and development of leading-edge technologies in science and engineering.
Get started accelerating your business through our deep expertise in R&D with AI, quantum computing, and space development; please get in touch with Daiphys today!
Daiphys Technologies LLC - https://www.daiphys.com/