GitHub - Notes By ShariqSP

GitHub

What is GitHub?

GitHub is a web-based platform used for version control and collaborative software development. It allows developers to host their code repositories, track changes, collaborate on projects, and manage software releases. Built on Git, an open-source version control system, GitHub simplifies the process of managing and sharing code across teams and individuals by providing a centralized place to store repositories.

Why Use GitHub?

GitHub is essential for any development process because it provides a seamless workflow for managing code changes, collaboration, and project documentation. It allows teams to work together on projects from different locations, track the history of changes, resolve conflicts, and keep everyone aligned. GitHub also offers integrations with CI/CD tools, enhancing the automation of testing, building, and deployment.

How is GitHub Useful in Testing Automation?

In testing automation, GitHub can be used to store test scripts, automation frameworks, and test reports. A typical scenario involves an automation team collaborating to create and maintain test cases for continuous testing. By using GitHub, teams can automate the process of triggering test runs when code is committed to the repository. CI/CD pipelines integrated with GitHub can execute test scripts every time there’s a code change, ensuring that the software is stable.

How to Create a Repository in GitHub

  1. Log in to your GitHub account.
  2. Click on the + (plus) icon at the top-right corner and select New Repository.
  3. Provide a name, description, and set the repository to Public or Private.
  4. Click Create repository.

What is EGit and How to Set it Up?

EGit is an Eclipse plugin that allows users to interact with Git repositories directly from the Eclipse IDE. To set it up, go to the Eclipse Marketplace, search for 'EGit', and install it. Once installed, you can clone, push, pull, and manage repositories directly within Eclipse.

Collaboration and Access with GitHub in Eclipse

To collaborate in GitHub using Eclipse, you need to generate an access token from GitHub and use it in place of your password for authentication in Eclipse. With this setup, multiple users can clone the repository, make changes, and push updates. In a scenario where two team members are working on the same project, user A pushes changes, and user B pulls them to stay up to date before pushing their own changes, preventing conflicts.

Basic Git Commands with Examples

  • git init: Initialize a new Git repository.
  • git clone <repository-url>: Clone a remote repository to your local machine.
  • git add <file>: Stage changes for commit.
  • git commit -m "message": Commit staged changes with a message.
  • git push: Push local commits to the remote repository.
  • git pull: Pull changes from the remote repository to your local branch.

Cloning, Committing, Pushing, and Pulling in Eclipse

In Eclipse, using EGit, you can easily clone a repository by selecting File > Import > Git > Projects from Git and entering the repository URL. Once cloned, commit changes by selecting files in the Project Explorer, right-clicking, and choosing Team > Commit. Use Team > Push to push your commits and Team > Pull to synchronize changes from the remote repository.

What is Git Stash?

Git stash allows you to temporarily store changes that are not ready to be committed. For example, if you’re working on a feature but need to switch to a different task, you can use git stash to save your progress and later apply those changes using git stash apply. Use cases include situations where you're midway through a task but need to update your local branch with the latest code from the remote repository.

What are Git Conflicts, and How Do You Resolve Them?

Conflicts occur when two users make changes to the same file or line of code. For example, if User A edits line 20 of a file and User B also edits line 20 and pushes it, User A will encounter a conflict when pulling the latest changes. To resolve conflicts, open the conflicted file, manually merge the differences, and commit the resolved file.

What is Branching, and Why Do We Need It?

Branching allows developers to work on different features or fixes in isolation without affecting the main codebase. For instance, a feature branch can be created for new functionality, allowing developers to work without disrupting the main branch. In Eclipse, you can create branches using EGit by selecting Team > Switch to > New Branch and pushing branches to remote repositories for collaboration.

Pull Requests for Code Review

A pull request (PR) is a mechanism for submitting code changes for review. Developers create a PR after completing a feature or fix on a branch. The team can then review the changes, discuss feedback, and approve the PR before merging it into the main branch. Pull requests facilitate collaboration and help ensure that only high-quality code is merged into the codebase.