Git
How to avoid merge commits
Download the latest commits
git remote update -pUpdate the local branch
git merge --ff-only @{u}If the above fails with a complaint that the local branch has diverged:
git rebase -p @{u}
git reset --hard HEAD~1
git reset HEAD~1Add
Adds co-author to your commit message. Handy for pair programming.
Commit message
Co-authored-by: Joel Califa <602352+califa@users.noreply.github.com>Push
In order to not override someone else commits(with force) in remote repository use:
git push --force-with-leaseReset
git reset HEAD~1where ~1 is a number of commits from HEAD
# hard reset (loosing files/changes)
git reset --hard HEAD~1Rebase
# on a remote branch
git pull --rebase
# on a master
git pull --rebase origin masterStash
# preview last stashed changes
git stash show -p stash@{0}Create named stash with adding files with hunks preview
git stash push -p -m "my awesome config"Checkout unwanted files
git checkout -- .Checkout to previous branch
git checkout -Edit last local commit message
git commit --amendGit log
To view a git log of just one user's commits:
git log --author="Alex"Commit
Empty commit
Is useful to re-trigger CI pipeline or any other cloud integrations.
git commit --allow-empty -m "Trigger something"Branch
Rename a local Git branch
Rename a current branch
git branch -m <newname>Rename a brach while pointed to any branch
git branch -m <oldname> <newname>Git global configurations
in ~/.gitconfig
To change your Git username and email
git config --global user.name "Alexander Grischuk"
git config --global user.email [your email address here]Enable git pull use rebase by default
git config --global pull.rebase trueis equivalent to running git pull --rebase every time.
git config --global push.default current~/.gitignore_global
Ignore IDEA files globally
echo ".idea" > ~/.gitignore_global
git config --global core.excludesfile ~/.gitignore_globalCreate a new .gitignore file fetched from the GitHub repo for a "node" js app
.gitignore file fetched from the GitHub repo for a "node" js appnpx gitignore nodeCreating a SSH Public Key on OSX
ssh-keygen -t rsa -b 4096Copy public SSH key and add it to the GitHub
pbcopy < ~/.ssh/id_rsa.pubUseKeychain: do not re-enter password while commiting/clonning
Add following to the ~/.ssh/config
Host *
AddKeysToAgent yes
UseKeychain yesAdd private key to keychain
ssh-add --apple-use-keychain ~/.ssh/<private_key>Make sure AddKeysToAgent is set to yes in ~/.ssh/config for this to work
How to resolve conflicts in yarn.lock
https://github.com/yarnpkg/yarn/issues/1776#issuecomment-269539948
git rebase origin/masterWhen the first conflict arises, I checkout the yarn.lock then re-perform the installation
git checkout origin/master -- yarn.lock
yarnThis generates a new yarn.lock based on the origin/master version of yarn.lock, but including the changes I made to my package.json. Then it's just a matter of:
git add yarn.lock
git rebase --continueRelease
Create a release tag
git tag <tagname>Push all tags
git push origin --tagsPush a single tag
git push origin <tag>List all tags
git tagClone
Get up to speed with partial clone and shallow clone
Clean up
clean unreachable object (sometimes speeds up .git)
git prune --dry-runclean outdated branches
git fetch --pruneAdvanced git
git-reflog- Manage reflog informationgit-bisect- Use binary search to find the commit that introduced a bug
Further reading
Last updated
Was this helpful?