You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

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

  1. Download Git from git-scm.com.
  2. Run the installer and follow the setup instructions.
  3. Choose the default terminal as "Git Bash" or "Command Prompt."
  4. 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

  1. Create a new file or modify an existing one:

    echo "Hello World" > hello.txt
    
  2. Check the status of changes:

    git status
    
  3. Add changes to the staging area:

    git add hello.txt
    
  4. 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)

  1. Go to your repository on GitHub/GitLab.
  2. Switch to the new branch and click "Create Pull Request."
  3. Describe the changes and submit the PR.
  4. 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

  1. Install Visual Studio Code:
    Download and install it from here.

  2. Enable Git in VS Code:

  • Open VS Code.
  • Press Ctrl + P (Windows/Linux) or Cmd + P (macOS) and type Git: Enable.
  • If Git is not detected, set the Git path in the settings.
  1. Cloning a Repository:
  • Open the Terminal in VS Code (Ctrl + ` ).
  • Run the following command:
    git clone https://github.com/USERNAME/REPOSITORY.git
    
  1. 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.
  1. Pushing Changes:
  • Click Sync in the Source Control tab, or run:
    git push origin main
    
  1. 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:

  1. Is Git installed?

    git --version
    
  2. Is Git recognized in the system path? (Windows)

    where git
    
  3. Is the repository initialized correctly?

    git status
    
  4. Are the correct credentials for GitHub/GitLab being used?
    If fatal: Authentication failed appears, check your SSH keys or personal access tokens.

  5. 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! 🚀