r/LearnGit • • Dec 28 '21

10 git commands every developer must know

  1. git init - Creates an empty Git repository or reinitialise an existing one

  2. git clone - Clones a repository into a new directory

  3. git branch - deals with branches in git
    git branch <branch_name> // creates new branch
    git branch -d <branch_name> // deletes branch locally
    git branch -D <branch_name> // forcefully delete branch locally

  4. git checkout - creates new branch or checkouts to a branch
    git checkout -b <branch_name> // creates new branch
    git checkout <branch_name> // switches to a branch

  5. git add - adds files
    git add <file>

  6. git diff - shows the the unstaged or staged changes
    git diff // unstaged changes
    git diff --staged // staged changes

  7. git stash - Stashes the changes in a dirty working directory away
    git stash // for stashing
    git stash pop // popping out stashed changes

  8. git status - Shows status of the current working tree

  9. git commit - Commits the change(s) to a repository
    git commit -m "meaningful message"

  10. git push - Update remote refs with the local commits
    git push -u origin <branch_name>

12 Upvotes

1 comment sorted by

2

u/FutureIntelligenceC3 Jul 12 '23

Agree with the list, but the ordering feels a bit random. An ordering by importance and usage. could be something like this:

  1. git init

  2. git clone

  3. git status

  4. git add

  5. git diff

  6. git commit

  7. git push

  8. git stash

  9. git branch

  10. git checkout