User Tools

Site Tools


git

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
git [2023/01/06 17:58] – Add mention you can pull --rebase if you feel lucky dblumegit [2024/04/11 16:58] (current) – [git at dlma.com] dblume
Line 1: Line 1:
 ====== git ====== ====== git ======
  
-Make the clone at the remote repository.+Make the clone of the remote repository.
  
 <code> <code>
Line 11: Line 11:
 </code> </code>
  
-Double checking the remote names...+If it's a huge repo, [[https://github.blog/2020-12-21-get-up-to-speed-with-partial-clone-and-shallow-clone/|consider blobless and single branch and no tags]], like so...
  
 <code> <code>
-git remote -v +git clone \ 
-origin  git@github.com:dblume/get-shit-done (fetch) +  --filter=blob:none \ 
-origin  git@github.com:dblume/get-shit-done (push) +  -b main \ 
-upstream        git://github.com/icambridge/get-shit-done (fetch+  --single-branch \ 
-upstream        git://github.com/icambridge/get-shit-done (push)+  --no-tags \ 
 +  --shallow-submodules \ 
 +  --recurse-submodules=os/components/toolchain \ 
 +  --recurse-submodules=':(exclude)**/porting_kit:' \ 
 +  git@fake.github.com:project/project.git
 </code> </code>
 +
 +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 61:
  
 <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  # (where origin is the name of the shared repo) $ git remote prune origin  # (where origin is the name of the shared repo)
 </code> </code>
Line 64: Line 77:
   $ 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 "origin/remote-branch" exists, then just:
 +
 +  $ 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 124:
 git switch main git switch main
 git branch -d bugfix/JIRA-1-new-bugfix git branch -d bugfix/JIRA-1-new-bugfix
 +git pull
 +</code>
 +
 +====== Resolving a Merge Conflict ======
 +
 +<code>
 +git mergetool (possibly with filename)  # Bring up the vim 3-way diff
 +
 +# +----------+-----------+------------------+
 +# | (others) | (common)  | (my most recent) |
 +# | LOCAL    | BASE      | REMOTE           |
 +# +-----------------------------------------+
 +# |                                         |
 +# | temp file with <<< ||| >>> diffs        |
 +# +-----------------------------------------+
 +
 +git commit -a -m "Resolved merge conflict"
 +</code>
 +
 +Possibly keep rebasing.
 +<code>
 +git rebase --continue
 git pull git pull
 </code> </code>
Line 132: Line 172:
 <code bash> <code bash>
 git pull --rebase  # --dry-run to test first git pull --rebase  # --dry-run to test first
 +</code>
 +
 +====== Applying changes in a stash to a changed file =====
 +
 +When ''git stash apply'' doesn't work: Show the stash changes and pipe that to patch. Now you have a patch you can apply.
 +
 +<code>
 +git stash show -p | patch -p0
 </code> </code>
  
Line 176: Line 224:
 </code> </code>
  
-could've used gitweb but I used GitHub-like [[https://github.com/klaussilveira/gitlist|gitlist]] at http://git.dlma.com.+Options are: 
 + 
 +  * chose GitHub-like [[https://github.com/klaussilveira/gitlist|gitlist]] for https://git.dlma.com, because it works on my shared server. 
 +  * [[https://www.reddit.com/r/selfhosted/comments/13hxnf4/selfhosted_git_services_you_dont_need_a_huge/|cgit]] might work 
 +  * [[https://gogs.io/|gogs]] 
 +  * [[https://git-scm.com/book/en/v2/Git-on-the-Server-GitWeb|GitWeb]] (the one built-in.) 
 + 
 + 
 +====== Limit scope of huge repos ====== 
 + 
 +Create a .gitconfig file at the base of your repo: 
 +<file git .gitconfig> 
 +[remote "origin"
 +    fetch = +refs/heads/main:refs/remotes/origin/main 
 +    fetch = +refs/heads/user/dblume/*:refs/remotes/origin/user/dblume/
 +    tagopt = --no-tags 
 +</file> 
 + 
 +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 
 +</code> 
 + 
 +The submodule one is an optimization for the more general: 
 +<code bash> 
 +git submodule update --recursive  # Add --init before --recursive on first time 
 +</code>
  
 ====== git vim mergetool on macOS ====== ====== git vim mergetool on macOS ======
git.1673056683.txt.gz · Last modified: 2023/04/12 20:44 (external edit)