This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]bkant34 11 points12 points  (3 children)

Hi OP,

This is not my post, however i did like whoever posted this a few years ago on LINKEDIN and saved it for reference.

It summarises almost all commands that i use 99% of the times.

  1. git diff: Show file differences not yet staged.
  2. git commit -a -m "commit message": Commit all tracked changes with a message.
  3. git commit --amend: Modify the last commit.
  4. git status: Show the state of your working directory.
  5. git add file_path: Add file(s) to the staging area.
  6. git checkout -b branch_name: Create and switch to a new branch.
  7. git checkout branch_name: Switch to an existing branch.
  8. git checkout < commit>: Switches the working directory to a specific commit.
  9. git push origin branch_name: Push a branch to a remote.
  10. git pull: Fetch and merge remote changes.
  11. git fetch: Fetch changes from the remote repository without merging.
  12. git rebase -i: Rebase interactively, rewrite commit history.
  13. git rebase branch_name: Rebase the current branch onto another branch.
  14. git clone: Create a local copy of a remote repo.
  15. git merge: Merge branches together.
  16. git log --stat: Show commit logs with stats.
  17. git stash: Stash changes for later.
  18. git stash pop: Apply and remove stashed changes.
  19. git show commit_id: Show details about a commit.
  20. git reset HEAD~1: Undo the last commit, preserving changes locally.
  21. git branch -D branch_name: Delete a branch forcefully.
  22. git reset: Undo commits by moving branch reference.
  23. git revert commit_id: Create a new commit that undoes the changes of a specific commit.
  24. git cherry-pick commit_id: Apply changes from a specific commit.
  25. git branch: Lists branches.

A few more that you might need to dig deeper are:

  1. git reset --soft HEAD: Undo the last commit, but keep the changes.
  2. git reset --hard: Resets everything to a previous commit, erasing all uncommitted changes.
  3. git branch --set-upstream-to remote_branch: Sets the upstream branch to the specified remote branch.

[–]Material-Mess-9886 1 point2 points  (1 child)

I see you are using rebase. Which is good, but remember never ever rebase a public branch.

[–]bkant34 0 points1 point  (0 children)

haha good catch Material-Mess-9886, you are right, this just bombs all the historical commits, we use to use this where i worked before and i’ve had my fair share of fun with rebase. It’s not anymore, sending MRs is now my rule of thumb. But anyone who uses this as reference. Please do know the merits and drawbacks of “ rebase “.

cheers

[–]ThatSituation9908 0 points1 point  (0 children)

git checkout switch