Git and GitHub 101: A Beginner's Guide to Version Control and Collaborative Development Part 1

Git and GitHub 101: A Beginner's Guide to Version Control and Collaborative Development Part 1

Introduction

Version control is crucial in software development for managing code changes effectively, ensuring stability, and facilitating collaboration. Git and GitHub are essential tools that streamline this process.

Git tracks changes and maintains code history, while GitHub provides a collaborative platform for sharing code and working together.

Imagine you're an intern, eager to contribute but accidentally crashing the system. Don't worry! With Git and GitHub, you have a safety net. These tools enable you to undo changes and restore stability.
In this beginner's guide, we'll dive into the basics of Git and GitHub.Let's get started on our journey to explore the power of Git and GitHub.

Key Terms and Concepts

Let's learn some basic terms___

GitHub: The most popular remote storage solution for git repos. It provides developers with tools for collaboration, code sharing, and project management.

Repository/Repo: It is a collation of files and folders.
Here are some repos: meilisearch ,go, etc.

Clone: It creates an exact copy of a remote repository on your local machine, allowing you to have a local version of the project's code.

Commit: Think as a snapshot of code changes that captures a specific state in the codebase's history.

Branch: A separate line of development within a repository, allowing you to work on new features or experiments independently.
Hard to understand let me make it easy for you.
Imagine collaborating on a project with a friend, where they focus on the front end while you handle the back end. To avoid disrupting each other's work, you create separate branches. This allows you to independently experiment, make changes, and test your code without affecting the main codebase. Later, when everything is ready, you can merge your branch's changes into the main code, combining the front-end and back-end seamlessly.

Push: Imagine you've made some changes to your code and you want to share those changes with others. Pushing allows you to send your local code updates to a remote repository, making them available to your team or collaborators.

Merge: Imagine you and your teammate have been working on separate branches, making independent changes to the codebase. Once both branches are ready to be combined, you perform a merge. This process combines the changes from one branch into another, integrating the code modifications seamlessly. The merge ensures that the final code includes the contributions from both branches, allowing for a unified and cohesive project.

Pull: Let's say your team members have made some changes to the codebase that you want in your local repository. Pulling retrieves those latest code updates from the remote repository and integrates them into your own local copy, ensuring you have the most up-to-date version of the code.

Pull Request: Let's get the Branch example here .you've been working on a separate branch of the project, making significant changes. Now you're ready to merge your branch into the main codebase. A pull request serves as a formal request to review and merge your changes. It allows others to provide feedback, discuss the modifications, and ultimately decide whether your code is ready to merge in the main project.

Oh, no there is so much theory. I am personally not a fan of reading theory.
Let's Get Hands-On: Creating Your First Git Repository.

How to Install Git and Create a GitHub Account

Go to this link to install Git on your machine.
And if you don't own a GitHub account go here and get one.

After downloading the git check the version. Open your terminal and type the below command

git version

If you get this you are good to go.

Create your first repo/repository

No to your GitHub account and create a new repository by clicking "New repository"

Give a name to your repo, a small description about it, and check the "Add a README file" and click on the "Create repository" button.

oho... congrats you have created your first repository.

Clone your repository to your local machine

To clone the repository go to your GitHub repo and get the HTTPs URL

Open your terminal and copy the below command to replace the URL with your repo URL.

git clone [HTTPS URL]

Now go to the Project folder/directory using

cd [your repo name]

Open the folder in your favorite IDE and do your changes.

Now there are a few steps that you have to flow.
step 1: To check the modified files and folders.use

git status

Here you can see I have added a new file to my project.
step 2: This is the step where you add your files and changes to the git.

git add .

Using add. you can add all the changes to your repo.

step 3: Commit the files: Execute the git commit command along with the -m flag to include a commit message. Use the present tense of the verb and be clear about the changes made. For instance:

git commit -m "added test.txt file"

Step 4: Verify remote repository name: Use the command git remote -v to view the remote repositories associated with your local repository. The remote repository name, often labeled as "origin," will be displayed along with its URL.

And lastly

Push changes to the remote repository: Execute the git push command, specifying the remote repository name and branch name.

git push origin master

Enter your username and password for GitHub – The password field will appear empty as you type but don't worry, your input is being recorded. Just hit Enter after entering your details. If you're using SSH, you can skip this step.

Now go to your GitHub and you can see your changes

In the next blog, we will discuss branching, fork, and pull requests.