Git Configuration

  • Set User Name and Email: Crucial for identifying your contributions. Use the following commands in your terminal:
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
  • The --global flag applies these settings to all your Git projects on this machine. If you use GitHub, consider using your GitHub email address.

Project Initialization

  • Choose Project Directory: Select the folder containing the files you want to manage with Git.

  • Open Terminal/Command Prompt: Navigate to your project directory using the terminal.

  • Initialize Git: Use the git init command. This creates a hidden .git folder within your project directory; this folder contains all the information Git needs to track your project. The change in directory color often indicates successful initialization.

    • To view the contents of the .git directory (on Linux/macOS systems):

      ls -la .git

Staging and Committing Files

  • Add Files to Staging Area: The staging area is a temporary holding place for files you want to include in the next commit. Use one of these commands:

    • git add <filename>: Adds a specific file.
    • git add . (or git add -A or git add --all): Adds all files in the current directory. The . is a shortcut for the current directory.
  • Commit Changes: Once files are staged, commit them with a descriptive message using:

    git commit -m "Your commit message"

    Replace "Your commit message" with a concise description of the changes you’ve made (e.g., “Initial project setup,” “Added feature X”).

Verifying Commits

  • View Commit History: Use git log to display the history of your commits. This confirms that Git is tracking your changes.

Tools:

  • Terminal: Git Bash (Windows), macOS Terminal, or Hyper (cross-platform) are recommended.
  • Code Editor: Visual Studio Code (or your preferred editor) is helpful for viewing and editing files within your project.

This process sets up your project for version control with Git. You can now use Git commands to track further changes, create branches, merge changes, and collaborate with others.