git commands
.git
├── branches
├── config
├── description
├── HEAD
├── hooks
│ ├── applypatch-msg.sample
│ ├── commit-msg.sample
│ ├── fsmonitor-watchman.sample
│ ├── post-update.sample
│ ├── pre-applypatch.sample
│ ├── pre-commit.sample
│ ├── pre-merge-commit.sample
│ ├── prepare-commit-msg.sample
│ ├── pre-push.sample
│ ├── pre-rebase.sample
│ ├── pre-receive.sample
│ └── update.sample
├── info
│ └── exclude
├── objects
│ ├── info
│ └── pack
└── refs
├── heads
└── tags
Ubuntu install
sudo add-apt-repository ppa:git-core/ppa
sudo apt update
sudo apt install git
Git practices
git init
echo 'test text' | git hash-object -w --stdin
git cat-file -t .git/objects/d6/..hash
git cat-file -p .git/objects/d6/..hash
find .git/objects -f
echo 'test text' > test.txt
git hash-object -w test.txt
git update-index --add --cacheinfo 100644 d6..hash
git write-tree
git ls-files -s
git config --global user.name "someone"
git config --global user.email "someone@example.com"
git config --global core.editor "vim"
git add .
git diff
show you any uncommitted changes since the last commitgit status
git stash
git stash pop
git stash list
git stash apply stash@{1}
git stash show -p
git stash branch feat/stylesheet stash@{1}
git stash drop stash@{1}
git stash clear
git clean
undoing uncommitted changesgit commit -m 'feat: #task-hash new features introduced'
git commit --amend -m 'issue: #task-hash some issue fixed'
git commit --amend --no-edit
–no-edit flag will allow you to make the amendment to your commit without changing its commit messagegit tag
To list stored tags in a repogit tag -a v1.4 -m "my version 1.4"
git tag -a -f v1.4 <commit_hash>
update an existing taggit tag -d v1.3
git remote -v
git remote add <name> <url>
git remote rm <name>
git remote rename <old_name> <new_name>
git remote show upstream
git remote -v show
git push
git push -u origin master
git push <remote> --all
git push <remote> --tags
git branch -a
git branch -D branch_name
git push origin :branch_name
a branch name prefixed with a colon to git push will delete the remote branchgit fetch -all --prune
git fetch coworkers_repo coworkers/feature_branch
git branch coworkers/feature_branch origin/develop
git checkout coworkers/feature_branch
git checkout -b local_feature_branch
git pull
git checkout -b develop
git checkout -b develop origin/develop
git blame -L 1,10 README.md
examine specific points of a file’s history and get context as to who the last author was that modified the linegit branch -m old_branch_name new_branch_name
git cherry-pick <commit_sha>
git reflog --relative-date
git log --graph --oneline --decorate -10 --after="2022-06-1"
git log --grep="<pattern>"
git log <hash_since>..<hash_until>
# Rebase current HEAD point and back one commit onto the origin/master branch
git rebase --onto origin/master HEAD~ HEAD
# Rebase current HEAD point and back 8 commits onto the origin/master branch
git rebase --onto origin/master HEAD~8 HEAD
# Rebase current branch "branch-name" and back 5 commits onto the origin/master branch
git rebase --onto origin/master branch-name~8 branch-name
# Push your change to the remote branch develop at the origin server
git push origin HEAD:develop
# These commands push a given <BranchToPush> to the remote master or remote develop branch
git push origin <BranchToPush>:develop
git push origin <BranchToPush>:master
# Show-Ref Commands, used to see all recent changes
git show-ref master
git show-ref HEAD
git show-ref branch
Submodule
# main repo
git remote add origin git@github.com:cu-ecen-aeld/assignment-1-username.git
git pull
# add submodule
git submodule add https://gitlab.com/buildroot.org/buildroot/
# or
git remote add assignments-base https://github.com/cu-ecen-aeld/aesd-assignments.git
# pulls the content locally to match the latest status at https://github.com/cu-ecen-aeld/aesd-assignments
git fetch assignments-base
# This command makes your master branch match the master branch
git merge assignments-base/master
# clones the `assignment-autotest` submodule and nested git repositories
git submodule update --init --recursive
# To clone a project with submodules
git clone --recurse-submodules git@github.com:cu-ecen-aeld/assignment-1-username.git
Github self-host runner
# Create a folder
$ mkdir actions-runner && cd actions-runner
Copied!# Download the latest runner package
$ curl -o actions-runner-linux-x64-2.322.0.tar.gz -L https://github.com/actions/runner/releases/download/v2.322.0/actions-runner-linux-x64-2.322.0.tar.gz
Copied! # Optional: Validate the hash
$ echo "b13b784808359f31bc79b08a191f5f83757852957dd8fe3dbfcc38202ccf5768 actions-runner-linux-x64-2.322.0.tar.gz" | shasum -a 256 -c
# Extract the installer
$ tar xzf ./actions-runner-linux-x64-2.322.0.tar.gz
# Configure
# Create the runner and start the configuration experience
$ ./config.sh --url https://github.com/cu-ecen-aeld/assignment-1-username --token token_provided_by_github
# Last step, run it!
$ ./run.sh
.github/workflows/github-actions.yml
name: assignment-test
on:
push:
tags-ignore:
- "*"
branches:
- "*"
jobs:
unit-test:
container: cuaesd/aesd-autotest:24-unit-test
runs-on: self-hosted
steps:
- uses: actions/checkout@v2
- name: Checkout submodules
run: git submodule update --init --recursive
- name: Run unit test
run: ./unit-test.sh
full-test:
container: cuaesd/aesd-autotest:24-assignment1
runs-on: self-hosted
steps:
- uses: actions/checkout@v2
- name: Checkout submodules
run: git submodule update --init --recursive
- name: Run full test
run: ./full-test.sh
ssh
ssh-keygen -t rsa -b 4096
ssh-keygen -t dsa
ssh-keygen -t ecdsa -b 521
ssh-keygen -t ed25519
Git Internals - Evnironment Variables
# verbose logging
GIT_CURL_VERBOSE=1 GIT_TRACE=1 git pull
## ssh debug
GIT_SSH_COMMAND="ssh -vvv" git --no-replace-objects ls-remote ssh://git@git.github.com/npm/ipqs_iam.git
Proxy config
# view
git config --glbal -l
# set proxy
git config --global http.proxy 127.0.0.1:59527
git config --global https.proxy 127.0.0.1:59527
npm config set proxy http://127.0.0.1:59527
npm config set https-proxy http://127.0.0.1:59527
# unset
git config --global --unset http.proxy
git config --global --unset https.proxy
windows git issue
# windows: \r\n unix: \r linux: \n
git config --global core.authocrlf true
# file perimission auto change
git config --add core.filemode false
git status | grep typechange | awk '{print $2}' | xargs git checkout
## soft link
# 1. find ln files 120000
git ls-files -s
# 2. edit ln files with `mklink`
mklink [/D] [/H] [/J] LINK TARGET
# 3. block ln files modification
git update-index --assume-unchanged