Skip to content
Andrei Montchik edited this page Jul 1, 2024 · 17 revisions

Install

  1. Create the source directory.
  2. sudo apt install git

Configure

  1. Update the Git configuration:
    git config --global user.email "andrei@montchik.net";
    git config --global user.name "Andrei Montchik";
    git config --global pull.rebase false;
    
  2. Confirm that the config change was applied: git config --list

Clone

  1. Add the SSH pubkey to GitHub account: https://github.com/settings/keys
  2. Check SSH access: ssh -vT git@github.com
  3. request to add your Git account as collabrator to GitHub repo
  4. Use SSH to clone GIT repos

Branch

  • Show: remote branches: git branch -r
  • Create:
    • Create Local Branch: git checkout -b
    • Push to remote repo: git push --set-upstream origin
    • Branch from the commit: git checkout -b
    • Check if remote branch exists: git branch -r | grep
  • Remove:
    • Local: git branch -d
    • Remote: git push origin --delete

Cleanup

  • git remote prune origin Or git fetch origin --prune
  • Remove all untracked files: git clean -fdx

Diff

  • File names only: git diff --name-only release/raptor
  • Specific file: git diff release/raptor raptor-cgw/api/src/main/scala/com/gemini/raptor/cgw/api/DomainEntries.scala
  • Between branches:
    1. git fetch
    2. git log --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --graph --grep="CGW" 'origin/release/2022-07-06'...'origin/release/2022-07-20'
  • Between commits:
    • git diff b509834813184d3be0f1e536ed9275ef2ec57610 80c88fb6c407135223644d0d99bb504d980bc4f1 --name-only
    • git diff b509834813184d3be0f1e536ed9275ef2ec57610 80c88fb6c407135223644d0d99bb504d980bc4f1 cpp/bin/env

Stash

  • Save: git stash push -m "my_stash"
  • View: git stash list
  • Pop: git stash pop --index
  • Remove all stashed: git stash clear

Commit

  • Add new files: git add .
  • Discard the uncommitted change: git checkout -- <filename>
  • Undo the last commit:
    • Preserve the changes as uncommitted: git reset --soft HEAD~1
    • Discard the changes: git reset --hard HEAD~1
  • Undo a single fileL git checkout [commit ID] -- path/to/file
  • Merge the specific commit: git cherry-pick <commit id>
  • Check which branches contains the commit: git branch -a --contains <commit id>
  • Show Last n commits: git log --pretty-oneline | head -n
  • Show all files in the commit: git show --pretty="" --name-only <commit id>
  • Show Commits containing the search line: git log -S LegacyMessageHandler

Signing Commits

Merge

Merge from the remote branch: git merge --no-edit origin/master git merge --no-ff --no-commit -s recursive -X patience origin/release/raptor

Push

Use git push --force-with-lease instead of git push --force to update a branch where you have changed history.

Tag

https://git-scm.com/book/en/v2/Git-Basics-Tagging

git tag -a -m git push origin to review: git show to checkout: git checkout

Clone this wiki locally