5.6 KiB
id | title | sidebar_label |
---|---|---|
git-workflow-vscode | Git & Pull Request Workflow | Git & Pull Requests |
📌 Git & Pull Request Workflow
Git is a distributed version control system commonly used in software development.
This guide explains the basic usage of Git, the workflow with Pull Requests, and the integration with Visual Studio Code.
📝 Prerequisites
- Installed Git (Download here)
- GitHub, GitLab, or Bitbucket account (for remote repositories)
- Basic knowledge of Terminal or CLI
- Optional: Visual Studio Code for an easier Git workflow
🔧 Step 1: Installing Git on Windows, Linux & macOS
1️⃣ Installing Git on Windows
- Download Git from git-scm.com.
- Run the installer and follow the setup instructions.
- Choose the default terminal as "Git Bash" or "Command Prompt."
- Verify Git installation:
git --version
2️⃣ Installing Git on Linux (Debian/Ubuntu)
sudo apt update && sudo apt install -y git
3️⃣ Installing Git on macOS
brew install git
🔧 Step 2: Configuring Git
After installation, configure Git with your name and email:
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
Verify your Git configuration:
git config --list
📂 Step 3: Creating & Cloning a Repository
1️⃣ Creating a New Repository
On GitHub, GitLab, or Bitbucket:
- Create a new repository with a name and an optional README file.
2️⃣ Cloning a Repository
To clone the repository locally:
git clone https://github.com/USERNAME/REPOSITORY.git
cd REPOSITORY
🔨 Step 4: Making Changes & Committing
-
Create a new file or modify an existing one:
echo "Hello World" > hello.txt
-
Check the status of changes:
git status
-
Add changes to the staging area:
git add hello.txt
-
Commit the changes:
git commit -m "Added my first file"
🔄 Step 5: Pushing Changes to the Remote Repository
To push changes to GitHub/GitLab:
git push origin main
If working on a new branch:
git push origin feature-branch
🌿 Step 6: Creating & Using Feature Branches
1️⃣ Creating a New Branch:
git checkout -b feature-new-feature
2️⃣ Making Changes and Committing:
git add .
git commit -m "Added a new feature"
3️⃣ Pushing the Branch to Remote:
git push origin feature-new-feature
🔄 Step 7: Creating a Pull Request (PR)
- Go to your repository on GitHub/GitLab.
- Switch to the new branch and click "Create Pull Request."
- Describe the changes and submit the PR.
- Wait for a code review and make any necessary adjustments.
🔄 Step 8: Merging a Pull Request
Once your PR is approved:
- Click Merge Pull Request.
- Optionally, delete the branch:
git branch -d feature-new-feature git push origin --delete feature-new-feature
🔄 Step 9: Keeping Your Repository Up-to-Date
If the main
branch has been updated, sync your local repository:
git checkout main
git pull origin main
If working on a branch, merge main
into it:
git checkout feature-new-feature
git merge main
If merge conflicts occur, resolve them and commit again.
💻 Using Git in Visual Studio Code
-
Install Visual Studio Code:
Download and install it from here. -
Enable Git in VS Code:
- Open VS Code.
- Press
Ctrl + P
(Windows/Linux) orCmd + P
(macOS) and typeGit: Enable
. - If Git is not detected, set the Git path in the settings.
- Cloning a Repository:
- Open the
Terminal
in VS Code (Ctrl + `
). - Run the following command:
git clone https://github.com/USERNAME/REPOSITORY.git
- Making Changes & Committing:
- Modify files in VS Code and save them.
- Open the Source Control sidebar (
Ctrl + Shift + G
) to see changes. - Click the
+
button to stage changes. - Enter a commit message and click
Commit
.
- Pushing Changes:
- Click
Sync
in the Source Control tab, or run:git push origin main
- Branching & Pull Requests:
- Click the current branch (bottom left in VS Code).
- Select Create New Branch.
- After making changes, push the new branch.
- Create a Pull Request on GitHub/GitLab, review, and merge.
🛑 Step 10: Troubleshooting (Common Issues)
If Git is not working, check:
-
Is Git installed?
git --version
-
Is Git recognized in the system path? (Windows)
where git
-
Is the repository initialized correctly?
git status
-
Are the correct credentials for GitHub/GitLab being used?
Iffatal: Authentication failed
appears, check your SSH keys or personal access tokens. -
Merge conflicts? If
CONFLICT (content)
appears, open the affected files in VS Code, resolve conflicts, and commit again.
✅ Conclusion
Now you are ready to use Git, efficiently work with Pull Requests, and integrate Git with Visual Studio Code.
For further reading, check the official documentation:
Happy Coding! 🚀