Skip to content
Andrei Montchik edited this page May 22, 2024 · 17 revisions

Install

  1. Create the source directory.
  2. sudo apt install git
  3. 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;
    
  4. Confirm that the config change was applied: git config --list
  5. Clone repo in by using the SSH path
  6. request to add your Git account as collabrator to GitHub repo

Clone the repo

  1. Use SSH to clone GIT repos
  2. Check SSH access: ssh -vT git@github.com

Configuration:

  • git config --global user.name "Your Name"
  • git config --global user.email youremail@example.com

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

Configure: https://gemini-spaceship.atlassian.net/wiki/spaces/DEV/pages/858859/Developer+Setup#DeveloperSetup-commit-signingGitCommitSigningConfiguration
Troubleshoot: https://gemini-spaceship.atlassian.net/wiki/spaces/DEV/pages/2323644429/Commit+signing+troubleshooting

Restart SSH Agent: killall ssh-agent; eval `ssh-agent -s`; /usr/bin/ssh-add -s /usr/local/lib/opensc-pkcs11.so
Disable GPG signing: git config --global commit.gpgsign false

Make sure that the signing is enabled: 
  git config --global commit.gpgsign
  should return `true`

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