docs/git/cheat-sheet.md
See also fixing commits
git add foo.pygit checkout -b new-branch-namegit checkout maingit checkout old-branch-namegit commit -m "topic: Commit message title."git commit --amend: Modify the previous commit.git config --global core.editor nanogit config --global core.symlinks truegit diffgit diff --cachedgit diff HEAD~2..git fetch origingit fetch upstreamgit grep update_unread_countsgit loggit pull --rebase: Use this. Zulip uses a rebase oriented workflow.git pull (with no options): Will either create a merge commit
(which you don't want) or do the same thing as git pull --rebase,
depending on whether you've configured Git properlygit push origin +branch-namegit rebase -i HEAD~3git rebase -i maingit rebase upstream/maingit reflog | head -10git remote -vgit reset HEAD~2git rm oops.txtgit show HEADgit show HEAD~~~git show maingit statusgit add foo.py: add foo.py to the staging areagit add foo.py bar.py: add foo.py AND bar.py to the staging areagit add -u: Adds all tracked files to the staging area.git checkout -b new-branch-name: create branch new-branch-name and switch to/check out that new branchgit checkout main: switch to your main branchgit checkout old-branch-name: switch to an existing branch old-branch-namegit commit -m "commit message": It is recommended to type a
multiline commit message, however.git commit: Opens your default text editor to write a commit message.git commit --amend: changing the last commit message. Read more heregit config --global core.editor nano: set core editor to nano (you can set this to vim or others)git config --global core.symlinks true: allow symbolic linksgit diff: display the changes you have made to all filesgit diff --cached: display the changes you have made to staged filesgit diff HEAD~2..: display the 2 most recent changes you have made to filesgit fetch origin: fetch origin repositorygit fetch upstream: fetch upstream repositorygit grep update_unread_counts web/src: Search our JS for references to update_unread_counts.git log: show commit logsgit log --oneline | head: To quickly see the latest ten commits on a branch.git log -p: show commit logs with changes; see the "secret" to reading it's outputgit pull --rebase: rebase your changes on top of main.git pull (with no options): Will either create a merge commit
(which you don't want) or do the same thing as git pull --rebase,
depending on whether you've configured Git properlygit push origin branch-name: push you commits to the origin repository only if there are no conflicts.
Use this when collaborating with others to prevent overwriting their work.git push origin +branch-name: force push your commits to your origin repository.git rebase -i HEAD~3: interactive rebasing current branch with first three items on HEADgit rebase -i main: interactive rebasing current branch with main branchgit rebase upstream/main: rebasing current branch with main branch from upstream repositorygit reflog | head -10: manage reference logs for the past 10 commitsgit remote -v: display your origin and upstream repositoriesgit reset HEAD~2: reset two most recent commitsgit rm oops.txt: remove oops.txtgit show HEAD: display most recent commitgit show HEAD~~~: display third most recent commitgit show main: display most recent commit on maingit status: show the working tree status, unstaged and staged files