Skip to content

Basics For beginners

Bernard Sibanda edited this page Sep 15, 2024 · 4 revisions

Here’s an overview and code examples for performing various tasks in Git and GitHub:

1. Git - Basic Setup

Before anything, you should configure your Git username and email.

installation https://git-scm.com/book/en/v2/Getting-Started-Installing-Git

Here are the steps to install Git on Windows, Linux, and Mac OS:


1. Installing Git on Windows:

Method 1: Git for Windows Installer

  1. Download Git:

  2. Run the Installer:

    • Once downloaded, run the .exe file.
    • Follow the instructions in the setup wizard.
    • Choose your preferred options for the following (default options work well):
      • Adjusting the path environment.
      • Choosing a default text editor.
      • Configuring the line ending conversions.
      • Other additional components and Git behavior.
  3. Complete Installation:

    • Once the installation is done, click "Finish."
  4. Verify the Installation:

    • Open Git Bash (installed with Git).
    • Run the command to check the version:
      git --version
    • If you see a version number, Git is successfully installed.

2. Installing Git on Linux:

Method 1: Using the package manager

  1. Update the system package index:

    • For Debian/Ubuntu-based systems:
      sudo apt update
    • For Red Hat/Fedora-based systems:
      sudo dnf update
  2. Install Git:

    • For Debian/Ubuntu-based systems:
      sudo apt install git
    • For Red Hat/Fedora-based systems:
      sudo dnf install git
    • For Arch-based systems:
      sudo pacman -S git
  3. Verify the Installation:

    • Run the following command to check the Git version:
      git --version

3. Installing Git on Mac OS:

Method 1: Using Homebrew (Recommended)

  1. Install Homebrew (if you don't have it):

    • Open the Terminal and paste the following command:
      /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  2. Install Git:

    • After Homebrew is installed, run the following command to install Git:
      brew install git
  3. Verify the Installation:

    • Check the Git version with:
      git --version

Method 2: Git via Xcode (Another Option)

  1. Install Git with Xcode Command Line Tools:
    • Open the Terminal and run:
      xcode-select --install
  2. Verify Installation:
    • After installation, check the version with:
      git --version

Following these steps will install Git on Windows, Linux, and Mac OS systems.

# Set up Git
git config --global user.name "Your Name"
git config --global user.email "[email protected]"

2. GitHub - Set Up and Authentication

First, ensure your GitHub repository is created. You can do this through the GitHub web interface or CLI.

Create a new repository on GitHub:

  1. Go to GitHub.
  2. Create a new repository by clicking New on your GitHub profile page.
  3. Choose a name, description, and whether it's private or public.
  4. Initialize with a README.md if you want.

You can authenticate using SSH or HTTPS.

# SSH Authentication (preferred for security)
ssh-keygen -t rsa -b 4096 -C "[email protected]"
# Copy the SSH key to GitHub (Settings -> SSH and GPG keys)
cat ~/.ssh/id_rsa.pub

# To clone using SSH
git clone [email protected]:yourusername/yourrepository.git

# HTTPS Authentication
git clone https://github.com/yourusername/yourrepository.git

Here are the steps to install Git on Windows, Linux, and Mac OS:


1. Installing Git on Windows:

Method 1: Git for Windows Installer

  1. Download Git:

  2. Run the Installer:

    • Once downloaded, run the .exe file.
    • Follow the instructions in the setup wizard.
    • Choose your preferred options for the following (default options work well):
      • Adjusting the path environment.
      • Choosing a default text editor.
      • Configuring the line ending conversions.
      • Other additional components and Git behavior.
  3. Complete Installation:

    • Once the installation is done, click "Finish."
  4. Verify the Installation:

    • Open Git Bash (installed with Git).
    • Run the command to check the version:
      git --version
    • If you see a version number, Git is successfully installed.

2. Installing Git on Linux:

Method 1: Using the package manager

  1. Update the system package index:

    • For Debian/Ubuntu-based systems:
      sudo apt update
    • For Red Hat/Fedora-based systems:
      sudo dnf update
  2. Install Git:

    • For Debian/Ubuntu-based systems:
      sudo apt install git
    • For Red Hat/Fedora-based systems:
      sudo dnf install git
    • For Arch-based systems:
      sudo pacman -S git
  3. Verify the Installation:

    • Run the following command to check the Git version:
      git --version

3. Installing Git on Mac OS:

Method 1: Using Homebrew (Recommended)

  1. Install Homebrew (if you don't have it):

    • Open the Terminal and paste the following command:
      /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  2. Install Git:

    • After Homebrew is installed, run the following command to install Git:
      brew install git
  3. Verify the Installation:

    • Check the Git version with:
      git --version

Method 2: Git via Xcode (Another Option)

  1. Install Git with Xcode Command Line Tools:
    • Open the Terminal and run:
      xcode-select --install
  2. Verify Installation:
    • After installation, check the version with:
      git --version

Following these steps will install Git on Windows, Linux, and Mac OS systems.

3. Raising Issues on GitHub

To raise an issue using the GitHub interface:

  1. Navigate to the repository.
  2. Click on the Issues tab.
  3. Click New Issue.
  4. Fill out the title and description.

You can also automate issues creation using GitHub API with curl or GitHub CLI.

# Using GitHub CLI
gh issue create --title "Bug: Description of the issue" --body "Steps to reproduce..."

4. Fork a Repository on GitHub

Forking a repository is done via the GitHub web interface:

  1. Go to the repository you want to fork.
  2. Click the Fork button in the top-right corner.

After forking, you can clone the forked repository.

# Clone the forked repo (assuming you forked via GitHub UI)
git clone [email protected]:yourusername/forked-repository.git

5. Clone a Repository

To clone a repository locally:

# Clone with HTTPS
git clone https://github.com/username/repository.git

# Clone with SSH
git clone [email protected]:username/repository.git

6. Creating a Pull Request

Pull requests (PRs) are created after you make changes in your forked or cloned repository and push them to a branch.

# Create a new branch
git checkout -b feature/my-new-feature

# Make your changes, add, and commit them
git add .
git commit -m "Added new feature"

# Push your changes to your GitHub repository
git push origin feature/my-new-feature

# Go to GitHub and create a pull request between your branch and the original repository's main branch.

Alternatively, you can use GitHub CLI:

# Push to GitHub and create a PR via CLI
gh pr create --title "Added new feature" --body "This PR adds a new feature for X functionality"

7. Peer Review - Do's and Don'ts

When reviewing code, keep these points in mind:

Do's:

  • Be respectful: Provide constructive feedback in a polite tone.
  • Be specific: Point out specific parts of the code that need improvements or are well-done.
  • Ask questions: If something is unclear, ask the author for clarification.
  • Check for consistency: Ensure the code follows the repository's style guidelines.

Don'ts:

  • Don’t be rude or dismissive: Avoid making personal attacks or dismissing ideas without providing a reason.
  • Avoid nitpicking: Focus on significant issues rather than minor stylistic preferences.
  • Don’t rush: Take your time to thoroughly review the code to catch potential issues.

8. Pair Programming

Pair programming involves two developers working together at one workstation. One developer, the "driver," writes code, while the other, the "navigator," reviews each line as it's written.

Setup for Remote Pair Programming:

You can use tools like VS Code Live Share, Tuple, or Visual Studio Live Share. Here's an example with VS Code Live Share:

  1. Install the Live Share extension:

    • In VS Code, go to the extensions tab and search for "Live Share."
    • Install it and sign in.
  2. Start a live sharing session:

    • Click on the "Live Share" button on the status bar.
    • Share the link with your pair programmer.

Both participants can code and review simultaneously.


Conclusion

This set of commands and tips should help you navigate common tasks in Git and GitHub, along with peer review and pair programming processes. Let me know if you need any clarifications or additional examples.

Clone this wiki locally