Configuration Steps
Required (For Fresh Install)
First, check if you have already configured Git by running:
git config --global --list
If the user.name and user.email configurations are empty, run the following commands to set them up:
git config --global user.name "Your Name"
git config --global user.email "
[email protected]"
Recommended
git config --global core.editor "code --wait" // Sets VS Code as the default editor
git config --global merge.tool "vscode" // Sets VS Code as the merge tool
git config --global mergetool.vscode.cmd "code --wait $MERGED" // Defines the command to open the merge tool in VS Code
Examples & Tutorial
This section provides a small tutorial demonstrating an end-to-end flow using the most common Git commands.
Step-by-Step Example
1. Initialize a new Git repository:
git init
This command creates a new Git repository in your current directory. A Git repository is a virtual storage of your project where you can keep track of changes.
2. Clone an existing repository:
git clone https://github.com/username/repo.git
This command copies an existing repository from the URL to your local machine. "Clone" means creating a copy of the repository so you can work on it locally.
3. Check the status of your repository:
git status
This command shows the state of your working directory and staging area. It lets you see which changes have been staged, which haven't, and which files aren't being tracked by Git.
4. Add a file to the staging area:
git add file.txt
This command adds the specified file to the staging area. The staging area is like a waiting room where your changes sit before you commit them.
5. Commit changes with a message:
git commit -m "Added file.txt"
This command saves your changes in the local repository. The message within quotes should describe the changes made, which helps in keeping track of your project's history.
6. Create a new branch and switch to it:
git branch new-feature
git checkout new-feature
The first command creates a new branch called "new-feature." A branch is a separate line of development. The second command switches to this new branch, allowing you to work on it independently of the main branch.
7. Push the new branch to the remote repository:
git push origin new-feature
This command uploads your new branch to the remote repository (e.g., GitHub). "Push" means sending your changes to the remote server so others can access them.
8. Create a Pull Request (PR) or Merge Request (MR):
Go to your remote repository (e.g., GitHub) and create a Pull Request (PR) or Merge Request (MR) from the new-feature branch to the main branch. This allows others to review your changes before merging.
9. Merge the new branch into the main branch after approval:
git checkout main
git pull origin main
Switch to the main branch and pull the latest changes. This ensures your local main branch is up to date.