How to Use Git from the Command Line

· Category: VS Code & Developer Tools

Short answer

Git is a distributed version control system managed from the command line. Learning the core commands lets you track changes, collaborate, and maintain project history.

Steps

  1. Install Git from git-scm.com and verify with git --version.
  2. Clone a repository with git clone <url>.
  3. Stage changes with git add <file> or git add . for all files.
  4. Commit changes with git commit -m "message".
  5. Push to remote with git push and pull updates with git pull.

Tips

  • Use git status frequently to see the current state of your working directory.
  • Write commit messages in the imperative mood: "Add feature" not "Added feature".
  • Configure your name and email with git config --global user.name and user.email.

Common issues

  • Merge conflicts occur when the same line is edited; resolve them manually in the file.
  • Authentication errors often mean your credentials or SSH keys need updating.