-
Notifications
You must be signed in to change notification settings - Fork 2
Basics For beginners
Here’s an overview and code examples for performing various tasks in Git and GitHub:
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:
-
Download Git:
- Visit Git for Windows and download the installer.
-
Run the Installer:
- Once downloaded, run the
.exefile. - 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.
- Once downloaded, run the
-
Complete Installation:
- Once the installation is done, click "Finish."
-
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.
- Open
-
Update the system package index:
- For Debian/Ubuntu-based systems:
sudo apt update
- For Red Hat/Fedora-based systems:
sudo dnf update
- For Debian/Ubuntu-based systems:
-
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
- For Debian/Ubuntu-based systems:
-
Verify the Installation:
- Run the following command to check the Git version:
git --version
- Run the following command to check the Git version:
-
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)"
- Open the Terminal and paste the following command:
-
Install Git:
- After Homebrew is installed, run the following command to install Git:
brew install git
- After Homebrew is installed, run the following command to install Git:
-
Verify the Installation:
- Check the Git version with:
git --version
- Check the Git version with:
-
Install Git with Xcode Command Line Tools:
- Open the Terminal and run:
xcode-select --install
- Open the Terminal and run:
-
Verify Installation:
- After installation, check the version with:
git --version
- After installation, check the version with:
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]"First, ensure your GitHub repository is created. You can do this through the GitHub web interface or CLI.
- Go to GitHub.
- Create a new repository by clicking
Newon your GitHub profile page. - Choose a name, description, and whether it's private or public.
- 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.gitHere are the steps to install Git on Windows, Linux, and Mac OS:
-
Download Git:
- Visit Git for Windows and download the installer.
-
Run the Installer:
- Once downloaded, run the
.exefile. - 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.
- Once downloaded, run the
-
Complete Installation:
- Once the installation is done, click "Finish."
-
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.
- Open
-
Update the system package index:
- For Debian/Ubuntu-based systems:
sudo apt update
- For Red Hat/Fedora-based systems:
sudo dnf update
- For Debian/Ubuntu-based systems:
-
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
- For Debian/Ubuntu-based systems:
-
Verify the Installation:
- Run the following command to check the Git version:
git --version
- Run the following command to check the Git version:
-
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)"
- Open the Terminal and paste the following command:
-
Install Git:
- After Homebrew is installed, run the following command to install Git:
brew install git
- After Homebrew is installed, run the following command to install Git:
-
Verify the Installation:
- Check the Git version with:
git --version
- Check the Git version with:
-
Install Git with Xcode Command Line Tools:
- Open the Terminal and run:
xcode-select --install
- Open the Terminal and run:
-
Verify Installation:
- After installation, check the version with:
git --version
- After installation, check the version with:
Following these steps will install Git on Windows, Linux, and Mac OS systems.
To raise an issue using the GitHub interface:
- Navigate to the repository.
- Click on the
Issuestab. - Click
New Issue. - 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..."Forking a repository is done via the GitHub web interface:
- Go to the repository you want to fork.
- Click the
Forkbutton 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.gitTo clone a repository locally:
# Clone with HTTPS
git clone https://github.com/username/repository.git
# Clone with SSH
git clone [email protected]:username/repository.gitPull 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"When reviewing code, keep these points in mind:
- 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’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.
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.
You can use tools like VS Code Live Share, Tuple, or Visual Studio Live Share. Here's an example with VS Code Live Share:
-
Install the Live Share extension:
- In VS Code, go to the extensions tab and search for "Live Share."
- Install it and sign in.
-
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.
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.