TBA
$ git clone --recursive REPO_ADDRESS
REPO_ADDRESS
- url/path to git repo--recursive
- option to download submodules (nested git repos included in a repo)
$ git clone --bare REPO_ADDRESS_SRC
$ cd SRC
$ git push --mirror REPO_ADDRESS_DST
REPO_ADDRESS_SRC
- url/path to source git repoREPO_ADDRESS_DST
- url/path to destination git repo (must exist but without any commit nor branch)
$ git pull
pull
=fetch
+merge
$ git fetch ORIGIN
$ git fetch --tags ORIGIN
$ git push --tags
$ git checkout --orphan EMPTY_BRANCH
$ git rm -rf .
$ rm ...
$ git commit --allow-empty -m "Init commit"
$ git push origin EMPTY_BRANCH
$ git checkout -b DST SRC
DST
- destination name for new local branchSRC
- commit/tag/branch from git repo
$ git push -u origin LOCAL_BRANCH
$ git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
$ git fetch upstream
Optionally (???):
$ git merge upstream/master master
or:
$ git rebase upstream/master
$ git worktree add PATH BRANCH
$ git checkout DST
$ git merge SRC
$ git push
DST
- destination branch merge toSRC
- source branch merge from
- if after non-conflicting changes/merges git shows something like:
On branch main
Your branch is up to date with 'upstream/main'.
You are currently rebasing branch 'BRANCH' on 'shaID'.
(all conflicts fixed: run "git rebase --continue")
nothing to commit, working tree clean
- then just do:
$ git rebase --abort
$ git branch -D BRANCH_TO_DELETE
$ git push origin -d BRANCH_TO_DELETE
$ git submodule update --init [--recursive]
--recursive
- option to download submodules (nested git repos included in a repo)
$ git submodule add -b BRANCH_TO_FETCH REPO_ADDRESS
$ git submodule init
- for the situation with a submodule like this one:
$ git status
On branch main
Your branch is up to date with 'origin/main'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: PATH/TO/LOCAL/SUBMODULE/IN/REPO (new commits)
no changes added to commit (use "git add" and/or "git commit -a")
$ git diff
diff --git a/PATH/TO/LOCAL/SUBMODULE/IN/REPO b/PATH/TO/LOCAL/SUBMODULE/IN/REPO
index SHA_N..SHA_M X
--- a/PATH/TO/LOCAL/SUBMODULE/IN/REPO
+++ b/PATH/TO/LOCAL/SUBMODULE/IN/REPO
@@ -1 +1 @@
-Subproject commit SHA_OLD
+Subproject commit SHA_NEW
- run:
$ git submodule update --recursive PATH/TO/LOCAL/SUBMODULE/IN/REPO
$ git reset --hard && git clean -x -f -d
$ git checkout -- FILE_NAME
- revert changes from a particular commit only by creating additional commit in git history:
$ git revert SHA_ID
- revert N commits (i.e., in case of 1 the latest commit only) by modifying commit history (rewind back git history by N commits basically):
$ git reset --hard HEAD~N
$ git show ID:path/to/file
where ID
is SHA ID of a commit or a branch name.
$ git rev-parse --short HEAD
$ git tag --points-at SHA_ID
$ git symbolic-ref --short HEAD
$ git TBA
$ git log --oneline main..branch
$ git log --oneline main..branch --names-only
- add to
core
section of~/.gitconfig
file:
[core]
autocrlf = input
TBA
- using shell command:
$ git config --global core.editor COMMAND
- add to
core
section of~/.gitconfig
file:
[core]
editor = COMMAND
- using shell commands:
$ git config --global diff.tool COMMAND
$ git config --global merge.tool COMMAND
$ git config --global --add difftool.prompt false
- using config: add to
diff
section of~/.gitconfig
file:
[diff]
tool = COMMAND
- add to
core
section of~/.gitconfig
file:
[core]
...
excludesfile = ~/.gitignore
- add list of must-to-be-ignored files in
~/.gitignore
file:
GPATH
GRTAGS
GTAGS
tags
cscope.in.out
cscope.out
cscope.po.out
- add to
credential
section of~/.gitconfig
file:
[credential]
helper = libsecret
uncommitted changes in a particular local file:
- create wiki for your cloned project
- clone wiki from forked repo and add remote for upstream:
git clone git@ssh.gihub.com:YOUR_USERNAME/FORKED_REPO.wiki.git
git remote add upstream https://github.com/ORIGINAL_USERNAME/ORIG_REPO.wiki.git
- fetch
upstream
git meta info:
git fetch upstream
- create branch with wiki from upstream:
git checkout -b upstream upstream/master
- switch back to your branch of forked wiki:
git checkout master
- merge changes from upstream wiki branch to your forked wiki branch:
git merge upstream
git commit -m "Merge from upstream to forked wiki"
If .github/workflows/push.yml
is being used for CI/CD purposes,
then during checkout on GitHub infrastructure
a git repo will be in detached state. To deal with this,
add sub-sections like these into steps
section:
- ...
- uses: actions/checkout@v4
with:
submodules: true
fetch-tags: true
fetch-depth: 0
- name: Set git meta info
run: echo "GITHUB_CI_PR_SHA=${{github.event.pull_request.head.sha}}" >> "${GITHUB_ENV}"
- ...
So after that, submodules, tags & full commit history will be available during build/test/etc,
and shell environment variable "${GITHUB_CI_PR_SHA}"
will be holding the full actual latest SHA ID commit.