Learn here The Most Useful Git Commands.
Creating Git aliases
Aliases are fantastic to save having to type extra keys when using Git. These are my favorites:
$ git config --global alias.ch checkout
$ git config --global alias.br branch
$ git config --global alias.co commit
$ git config --global alias.st status
Creating a new branch from an upstream branch
You may want to pull in some code on a new laptop or a new workspace. In that case, to avoid confusion, it’s useful to recreate a similarly named local branch as you have in your remote repo.
Check the name of the branch that you want to create by
git branch -a
And create your new local branch by pulling down remote like this
git ch -b tests remotes/origin/tests
Check out the full example below
nikolayadvolodkin@SL-1506 portfolio % git branch -a * main remotes/origin/HEAD -> origin/main remotes/origin/main remotes/origin/tests nikolayadvolodkin@SL-1506 portfolio % git ch -b tests remotes/origin/tests
Fork and branch Git workflow
This workflow is great when you have a public repository that you want others to commit to. Or when you want to contribute to someone’s repository.
9. Pull changes from the original repository’s master branch to your local cloned repository
git pull upstream master
10. Delete the feature branch
git branch -d <you branch name>
11. Update the master branch in your forked repository
git push origin master
12. Delete the origin branch
git push –delete origin <branch name>
How to reset your local master branch to the forked repo’s master branch?
Sometimes you can do a git pull upstream master and really mess up with the automatic merge. In that case, you may just want to take the latest code from the fork. Use
# ensures current branch is master git checkout master # pulls all new commits made to upstream/master git pull upstream master # this will delete all your local changes to master git reset --hard upstream/master # take care, this will delete all your changes on your forked master git push origin master --force
How to store credentials through command line?
git config credential.helper store
How to delete all changes in current branch?
Discard all local changes to all files permanently
git reset --hard
How to fix: “fatal: Authentication failed for https://github.com/”
This article does an awesome job of showing you how to fix that problem
How to fix merge conflicts
git fetch origin
git checkout -b jest_start origin/jest_start
git merge master