Welcome! This is a cookbook for Git, with animated recipes for the most common tasks.
git switch feature/exampleThis will make the latest commit on the feature branch the new HEAD.
git merge mainIf your branches had diverged before the merge, a merge commit will be created. In this case, you will be prompted to enter a commit message. Otherwise, your branch will be fast-forwarded, and no merge commit will be created.
If prompted, enter the commit message for the merge commit. Running this command may open a text editor, which by default is the terminal-based text editor Vim. If you're not familiar with Vim, I highly recommend configuring your text editor to something you're already comfortable with. To get out of Vim, press Escape, then type :q! and press return.
git config --global core.editor "code --wait"If you use a different editor, you gotta figure out how to run it from the command line. To do this, just search the web for "run [your editor] from the command line". For example, for IntelliJ IDEA, you could run "idea --wait". For some editors, you might have to install a command line tool first.
git config --global core.editor "[your command]"The video to the right is timestamped and will take you to the exact point where I show you how to change the default text editor.
git config --global alias.SHORTCUT "FULL_COMMAND"For example, to map git status -s to git st, run:
git config --global alias.st "git status -s"From now on, you can always use git st instead of git status -s.
git config --global --editMake sure to configure your text editor to something you're already comfortable with before running this command.
[alias] st = status -s sta = status conf = config --global --edit cge = config --global --edit ci = commit co = checkout cod = checkout . rh = reset HEAD aa = add -A cdf = clean -df br = branch bra = branch -a pr = pull --rebase amend = commit -a --amend --no-edit ciam = commit -a --amend --no-edit
git stash push -m "MESSAGE"This makes it easier to see which changes are contained in the stash, similar to a commit message.
git stash applyBoth of these commands can also be used with a specific stash that you retrieved with git stash list, for example:
git stash pop stash@{1}
git stash apply stash@{1}
git log --oneline --branches --not --remotesAny commits listed here have not yet been pushed and are safe to reset. However, if this command returns nothing or your commit is not listed, you definitely should not reset it and use revert instead.
git reset HEAD~NThis will remove the commits from the current branch, but leave the changes in the working copy.
git revert --no-edit COMMIT_HASHThis will create a new commit that undoes all the changes from the specified commit. You can find the commit hash by running git log --oneline.
git rebase -i HEAD~Nwhere N is the number of commits you want to edit. For example: git rebase -i HEAD~4 will let you edit the last 4 commits. This will open your text editor with a list of commits. For each commit, you can: