Git Commands

1. Clone Git Repository to your local machine

git clone https://github.com/yourrepository

2. Git create a branch

git checkout -b hotFix

3. Git remove a file

git rm "file name"

4. Git add all edited files to queue

git add .

5. Remove from add

git reset

6. Commit changes

git commit -m "Your Message"

7. Create new repo

git init

8. Clone remote repo

git clone <url>

9. Show changes

git status

10. Stage a file

git add <file>

11. Stage all changes

git add .

12. Commit staged changes

git commit -m "msg"

13. Stage tracked + commit

git commit -am "msg"

14. Compact history view

git log --oneline --graph

15. Show unstaged changes

git diff

16. Show staged vs last commit

git diff --staged

17. List branches

git branch

18. Create branch

git branch <name>

19. Switch branch

git switch <name>

20. Create + switch

git switch -c <name>

21. Old way to switch branch

git checkout <name>

22. Delete branch

git branch -d <name>

23. Show remotes List all configured remotes

git remote -v

24. Update current branch

git pull

25. Rebase instead of merge

git pull --rebase

26. Push current branch

git push

27. First push + set upstream

git push -u origin <branch>

28. Merge into current

git merge <branch>

29. Rebase onto branch

git rebase <branch>

30. Apply specific commit

git cherry-pick <commit>

31. Discard local changes

git restore <file>

32. Unstage all staged files in the current directory

git restore --staged

33. Unstage file

git restore --staged <file>

34. Unstage file

git reset <file>

35. Reset everything to last commit

git reset --hard HEAD

36. Undo commit with new commit

git revert <commit>

37. Change commit message

git commit --amend

38. Stash changes

git stash

39. List stashes

git stash list

40. Apply + remove stash

git stash pop

41. List tags

git tag

42. Create tag

git tag <name>

43. Push tag

git push origin <name>

44. Show public history

git log -g

45. Show private history

git reflog

46. Remove untracked files/dirs

git clean -fd