Created
December 27, 2021 02:19
-
-
Save tomstorms/5af27c462912d2fb8e2aaedc8fd53b93 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#----------------------------------------------------- | |
# Create a new repo: | |
# | |
# For basics, see: https://towardsdatascience.com/common-github-commands-every-data-scientist-needs-to-know-e7d5d9c4f080 | |
# | |
git init | |
#----------------------------------------------------- | |
# Setup a repo with remote branch: | |
echo "# article" >> README.md | |
git init | |
git add README.md | |
git commit -m "first commit" | |
git remote add origin https://github.com/mprzybyla123/article.git | |
git push -u origin master | |
#----------------------------------------------------- | |
# add origin to an existing repo: | |
# "fatal: refusing to merge unrelated histories" | |
git pull origin master --allow-unrelated-histories | |
#----------------------------------------------------- | |
# add origin to an existing repo: | |
# "fatal: Not possible to fast-forward, aborting." | |
git config pull.rebase true | |
git pull origin master --allow-unrelated-histories | |
#----------------------------------------------------- | |
# rebase and fast forward: | |
git config pull.rebase false # merge (the default strategy) | |
git config pull.rebase true # rebase | |
git config pull.ff only # fast-forward only | |
#----------------------------------------------------- | |
# Show all branches | |
git branch -a | |
#----------------------------------------------------- | |
# what is my current branch? | |
git branch | |
#----------------------------------------------------- | |
# force git pull and overwrite all changes: | |
git pull | |
git fetch --all | |
git reset --hard | |
#----------------------------------------------------- | |
# switch branch | |
git checkout <branch-name> | |
#----------------------------------------------------- | |
# switch branch with remote | |
git checkout --track origin/orange-login-checkout | |
#----------------------------------------------------- | |
# get the status of the repo | |
git status | |
#----------------------------------------------------- | |
# get last commit hash | |
git log -n 1 | |
#----------------------------------------------------- | |
# commit all changes with a message | |
git add -A | |
git commit -a -m "Committing latest jarvis dev changes" | |
git push | |
#----------------------------------------------------- | |
# amend a commit message | |
git commit --amend -m "New commit message." | |
#----------------------------------------------------- | |
# remove untracked files | |
git clean -f | |
#----------------------------------------------------- | |
# temporarily use another ssh key | |
ssh-agent sh -c 'ssh-add ~/.ssh/id_rsa; <git-command-here>' | |
#----------------------------------------------------- | |
# git using different commiter details: | |
git -c "user.name=Your Name" -c "user.email=Your email" commit ... | |
example: | |
git -c "user.name=twentytwodigital" -c "[email protected]" commit -m "COMMIT_MESSAGE" | |
#----------------------------------------------------- | |
# revert the last git commit: | |
git reset --hard HEAD~1 | |
# or | |
git reset --hard <sha1-commit-id> | |
git push origin HEAD --force | |
#----------------------------------------------------- | |
# clone using a ssh key: | |
git clone [email protected]:orgname/gitrepo.git --config core.sshCommand="ssh -i /Users/tom/.ssh/private-key" | |
if you get prompted for a password, change the remote origin url to use SSH instead of HTTPS (ie [email protected]:orgname/repo.git instead of https://github.com/orgname/repo.git | |
#----------------------------------------------------- | |
# To skip husky commit checks, add: | |
--no-verify | |
or delete the .husky folder | |
#----------------------------------------------------- | |
# To install husky | |
npx husky-init && yarn | |
#----------------------------------------------------- | |
# Update author commit date: | |
git commit --amend --date="YYYY-MM-DD HH:MM:SS" | |
#----------------------------------------------------- | |
# Git restore a single file or path: | |
git checkout -- /path/to/file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment