hjaltiatlason

my_git_command_cheat_sheet

Aug 5th, 2020 (edited)
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. Most used git commands
  2. =======================
  3.  
  4. git init [project name] # From scratch -- Create a new local repository
  5. git status #List new or modified files not yet commited
  6. git log # Show full change history
  7. git add . # Stage all changed files ready for commit
  8. git commit -m "added Day-1 projects" # Commit all staged files to versioned history
  9. git remote add origin remote repository URL #Sets the new remote
  10. git remote -v # Verifies the new remote URL
  11. git push origin main # Push local changes to the origin
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18. Working with branches
  19. =======================
  20. git branch # list all local branches
  21. git cranch -av # list all branches , local and remote
  22. git checkout my_branch # switch to a branch, my_branch and update working directory
  23. git branch new_branch #create a new branch called new_branch
  24. git branch -d my_branch # delete the branch called my_branch
  25.  
  26. #merge branch_a into branch_b
  27. git checkout branch_b
  28. git merge branch_a
  29.  
  30. #Merge vs Rebase
  31. git merge test
  32. git rebase test
  33.  
  34.  
  35. Synchronize
  36. ============
  37. git fetch #Get the latest changes from origin (no merge)
  38. git pull #Fetch the latest changes from origin and merge
  39. git pull --rebase # fetch the latest changes from origin and rebase
  40.  
  41. Rolling Back
  42. ==============
  43. git log # Check our previous commits and their hashes
  44. git revert Hash # Rollback to previous commit
  45. git checkout Hash # Check out previous commits # git checkout master #to switch back to the branch you werer working in
  46.  
  47.  
  48.  
  49.  
Advertisement
Add Comment
Please, Sign In to add comment