Skip to content

Git Commands

  1. Clone the repository:

    Terminal window
    git clone <repoUrl>
  2. Check out an existing branch or create a new one:

    Terminal window
    git checkout <branchName>
    # or create a new branch
    git checkout -b <newBranchName>
  3. Check your current branch and staged changes:

    Terminal window
    git status
  4. Stage your changes:

    Terminal window
    git add --all
    # or stage a specific file
    git add <filePath>
  5. Commit staged changes:

    Terminal window
    git commit -m "commit message"
  6. Push to remote:

    Terminal window
    # First push on a new branch
    git push -u origin <branchName>
    # Subsequent pushes
    git push
  • git pull — pull latest changes from remote into your local branch
  • git fetch — fetch remote changes without merging them into your local environment
  • git merge <branchName> — merge another branch into your current branch
  • git rebase <branchName> — rebase your current branch on top of another branch
  • git branch -d <branchName> — delete a local branch
  • git push origin --delete <branchName> — delete a remote branch
  • git reset --hard — discard all uncommitted changes