git
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| git [2023/01/06 17:58] – Add mention you can pull --rebase if you feel lucky dblume | git [2025/11/16 23:35] (current) – dblume | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== git ====== | ====== git ====== | ||
| - | Make the clone at the remote repository. | + | ===== Building Git ===== |
| + | |||
| + | In Ubuntu, get some dev libs first: | ||
| + | |||
| + | <code bash> | ||
| + | sudo apt-get install libssl-dev libcurl4-gnutls-dev gettext | ||
| + | </ | ||
| + | There was [[https:// | ||
| + | <code bash> | ||
| + | git clone --filter=blob: | ||
| + | # or: git clone --branch v2.50.1 --depth 1 https:// | ||
| + | # or even: wget https:// | ||
| + | |||
| + | make prefix=$HOME/ | ||
| + | make prefix=$HOME/ | ||
| + | </ | ||
| + | |||
| + | This will put git in '' | ||
| + | |||
| + | ===== Using Git ===== | ||
| + | |||
| + | Make the clone of the remote repository. | ||
| < | < | ||
| Line 11: | Line 32: | ||
| </ | </ | ||
| - | Double checking the remote names... | + | If it's a huge repo, [[https:// |
| < | < | ||
| - | $ git remote | + | git clone \ |
| - | origin | + | |
| - | origin | + | -b main \ |
| - | upstream | + | --single-branch \ |
| - | upstream | + | --no-tags \ |
| + | | ||
| + | --recurse-submodules=os/components/toolchain \ | ||
| + | | ||
| + | git@fake.github.com:project/project.git | ||
| </ | </ | ||
| + | |||
| + | Eventually, if you want to add another branch to a single-branch clone: | ||
| + | |||
| + | git remote set-branches --add origin another-branch | ||
| + | |||
| + | Or to de-single-branch-ize a clone: | ||
| + | |||
| + | git remote set-branches origin " | ||
| + | |||
| ===== Creating a new remote repository from an existing local one ===== | ===== Creating a new remote repository from an existing local one ===== | ||
| Line 48: | Line 82: | ||
| <code bash> | <code bash> | ||
| - | $ git fetch --all # TODO investigate why fetch | + | $ git fetch --all # Bring your copy of the remote up-to-date |
| $ git remote prune origin | $ git remote prune origin | ||
| </ | </ | ||
| Line 64: | Line 98: | ||
| $ git push --set-upstream origin new_branch | $ git push --set-upstream origin new_branch | ||
| + | ==== Creating a local branch from an existing remote ==== | ||
| + | |||
| + | After doing a fetch, and suppose " | ||
| + | |||
| + | $ git switch remote-branch | ||
| ==== Changing a local branch to a new remote branch ==== | ==== Changing a local branch to a new remote branch ==== | ||
| Line 106: | Line 145: | ||
| git switch main | git switch main | ||
| git branch -d bugfix/ | git branch -d bugfix/ | ||
| + | git pull | ||
| + | </ | ||
| + | |||
| + | ====== Resolving a Merge Conflict ====== | ||
| + | |||
| + | < | ||
| + | git mergetool (possibly with filename) | ||
| + | |||
| + | # +----------+-----------+------------------+ | ||
| + | # | (others) | (common) | ||
| + | # | LOCAL | BASE | REMOTE | ||
| + | # +-----------------------------------------+ | ||
| + | # | | | ||
| + | # | temp file with <<< | ||
| + | # +-----------------------------------------+ | ||
| + | |||
| + | git commit -a -m " | ||
| + | </ | ||
| + | |||
| + | Possibly keep rebasing. | ||
| + | < | ||
| + | git rebase --continue | ||
| git pull | git pull | ||
| </ | </ | ||
| Line 132: | Line 193: | ||
| <code bash> | <code bash> | ||
| git pull --rebase | git pull --rebase | ||
| + | </ | ||
| + | |||
| + | ====== Applying changes in a stash to a changed file ===== | ||
| + | |||
| + | When '' | ||
| + | |||
| + | < | ||
| + | git stash show -p | patch -p0 | ||
| </ | </ | ||
| Line 162: | Line 231: | ||
| git$ cd testcode.git/ | git$ cd testcode.git/ | ||
| testcode.git$ git init --bare | testcode.git$ git init --bare | ||
| + | testcode.git$ git config pack.threads 8 # Otherwise clone might fail with " | ||
| </ | </ | ||
| Line 176: | Line 246: | ||
| </ | </ | ||
| - | I could' | + | Options are: |
| + | |||
| + | * I chose GitHub-like [[https:// | ||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | |||
| + | |||
| + | ====== Limit scope of huge repos ====== | ||
| + | |||
| + | Create a .gitconfig file at the base of your repo: | ||
| + | <file git .gitconfig> | ||
| + | [remote " | ||
| + | fetch = +refs/ | ||
| + | fetch = +refs/ | ||
| + | tagopt = --no-tags | ||
| + | </ | ||
| + | |||
| + | Or explicitly specify your flags: | ||
| + | <code bash> | ||
| + | git fetch --no-tags origin main | ||
| + | git pull --no-tags origin main | ||
| + | git submodule foreach git pull --no-tags origin main | ||
| + | </ | ||
| + | |||
| + | The submodule one is an optimization for the more general: | ||
| + | <code bash> | ||
| + | git submodule update --recursive | ||
| + | </ | ||
| + | |||
| + | ====== Submodules ====== | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | Cloning a repo doesn' | ||
| + | |||
| + | <code bash> | ||
| + | git submodule update --init --recursive | ||
| + | </ | ||
| + | |||
| + | Git pull and checkout don't update submodules. To actually update them, you have to run the following every time you switch branches or pull. | ||
| + | |||
| + | <code bash> | ||
| + | git submodule update --recursive | ||
| + | </ | ||
| + | |||
| + | ====== You Don't Need GitHub ====== | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | * Set "git config receive.denyCurrentBranch updateInstead" | ||
| + | * Create a .git/ | ||
| + | * Tell git to host the remote repo with "git update-server-info" | ||
| ====== git vim mergetool on macOS ====== | ====== git vim mergetool on macOS ====== | ||
git.1673056683.txt.gz · Last modified: 2023/04/12 20:44 (external edit)