Basic Git Command Examples

  1. git init:
    • Usage: git init
    • Description: Initializes a new Git repository in the current directory.
  2. git clone:
    • Usage: git clone <repository-url>
    • Description: Creates a local copy of a remote repository on your machine.
    • Example: git clone
  3. git add:
    • Usage: git add <file>
    • Description: Stages changes or new files to be committed.
    • Example: git add index.html (stages the file “index.html” for commit)
  4. git commit:
    • Usage: git commit -m "commit message"
    • Description: Commits the staged changes, creating a new revision in your repository.
    • Example: git commit -m "Add new feature"
  5. git push:
    • Usage: git push origin <branch>
    • Description: Uploads your committed changes to a remote repository.
    • Example: git push origin main (pushes committed changes to the “main” branch of the remote repository)
  6. git pull:
    • Usage: git pull origin <branch>
    • Description: Retrieves the latest changes from a remote repository and merges them into your local branch.
    • Example: git pull origin main (pulls and merges changes from the “main” branch of the remote repository into the current branch)
  7. git branch:
    • Usage: git branch
    • Description: Lists existing branches in your repository.
    • Example: git branch (displays a list of branches)
  8. git merge:
    • Usage: git merge <branch>
    • Description: Integrates changes from one branch into another.
    • Example: git merge feature-branch (merges changes from the “feature-branch” into the current branch)
  9. git status:
    • Usage: git status
    • Description: Provides information about the current state of your repository.
    • Example: git status (displays the status of files, showing modified files, staged changes, etc.)
  10. git log:
    • Usage: git log
    • Description: Displays a chronological list of commits.
    • Example: git log (displays the commit history)

These examples should give you a good starting point for using Git and navigating basic version control tasks. Remember to adapt the commands and options to your specific repository and workflow.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.