Overviewing Git and GitHub

Overviewing Git and GitHub

Introduction to Git

A distributed version control system is called Git. What Exactly Is a Version Control System, then?

When working as a team or alone, a version control system is a system that keeps track of various versions of your project. As the project advances, additional features are added to the system that manages file modifications. Therefore, a version control system keeps track of all the various versions of your project for you, allowing you to roll back to any version you desire without having to deal with the hassle of keeping track of various versions under names like MyPrJ, MyPrjFtr1, etc.

With a distributed version control system, each developer working on a team project has a local repository of the project on his or her own computer as opposed to a central repository, where team members must constantly have an internet connection to update their work.

Distributed then means that the project is spread out. You should keep all of your project files, photos, and other materials in a repository. According to Github, commits correspond to various project versions.

In the software development process, Git and GitHub have gained popularity as industry standards. Here's a primer on how to use both to create applications and write code.

Introduction to GitHub

GitHub is essentially a service that lets you host your Git repositories online and work with others on them. In addition to its desktop GUI and Git Shell, GitHub also offers a web interface.

With 12 million developers and businesses using its service, GitHub has established itself as a reasonably common standard for project collaboration and code open-sourcing.

Explaining Git and GitHub

Git is a distributed version management system that is free and open source. Version control definition In essence, it's a system that enables you to keep track of changes made to files over time so that you may later see particular versions of those files.

Git has developed into a development industry standard over time. As your codebase expands and you need to refer to earlier versions of it, having the ability to take a snapshot of your code at a particular moment is quite valuable.

Using the "Git Shell," a command-line tool (you can use Git in different command-line tools; I'll refer to Git Shell throughout the next sections), you can use Git to track local changes to your code. Instead of using a graphical user interface, the command line enables you to type commands to view, modify, and manage files and folders in a straightforward terminal (GUI). Don't worry if you have never used the command line before; once you get going, it is really simple.

In essence, Git allows you to modify your code files the same way you would normally do so throughout the development process. When you finish a development milestone or wish to take a snapshot of specific changes, you add the modified files to a staging area and use Git to add them to the project's (repository's) version history. You may read more about the Git commands used for those steps in the section below.

Terminal Instructions While navigating through your project and system files and folders while using Git on the command line, it's likely that you'll also use a few standard terminal commands, such as:

Check your location in the current file system with pwd.

List the current directory's files with ls (folder)

Moves to the specified directory or path with the command cd [directory-name].

Mkdir creates a new directory with the specified name.

Establishing Repositories The first command you need to run when you want to use Git for a project is git init with the project name:

git init [project-name]

Git and GitHub can be used in countless ways, but getting started with GitHub doesn't have to be difficult. You don't have to be a master programmer or anything. Even the most crucial tasks can be completed directly from the GitHub website!

Finding your terminal and being just a little bit familiar with it is therefore a good idea. Things move along so much faster with terminal commands! I'll undoubtedly walk you through utilizing the GitHub website.

Some Basic Terminology

Repository: often known as a repo, is a folder that Git has been instructed to use to track file changes.

Branch: A separate line of development is referred to as a branch. It can be compared to a fresh working directory.

Fork: On your account, a fork is a personal copy of another user's repository.

Clone: A replica of a repository that resides on your computer rather than a server is called a clone.

A commit is a group of one or more file modifications (or a set of files). It generates a distinct ID (a "hash") each time you save, which aids in keeping track of the past.

Master: The main branch for development. A branch called "master" is automatically established whenever you create a git repository and it becomes the active branch by default.

Installation

Git for Windows should be downloaded and installed. Once it's installed, you can use Git in PowerShell or the command line.

Git does not update itself automatically on Windows. Download the most recent version to update it.

macOS Run the following commands to install the most recent version of Git on your Mac after installing Homebrew.

\> brew install git

To update your Git install, use Homebrew’s upgrade option:

\> brew upgrade git

Setting up Git After installing Git, run the following commands from the command prompt to set up this data:

\> git config --global user.name "user name"> git config --global user.email "user email"

Commands for Git Create a new repository from an existing folder on your computer by using the git init command. Navigate to the root folder containing your code from the command line and execute:-

\> git init

with git add move changes from the working directory to the staging area.

\> git add .

A git commit commits the staged files to the project history after taking them. This saves your modifications in the main repository together with git add.

\> git commit -m "commit message"

To replicate the contents of an existing repository to a folder on your computer, use the git clone command. Navigate to the location you want to house the cloned repository from the command line, then execute:

\> git clone (URL of the repo)

create branches using the git branch command:

\> git branch <branchname>

Use the git push to save your changes on the server.

\> git push origin <branchname>

To keep the local repository in sync with the remote repository

\> git pull origin master

Conclusion

In a nutshell, that is GitHub. Version control is the act of pushing and pulling code. Coders make sure that their version is the most recent at every stage. You can occasionally go back to older iterations of the code to fix mistakes if you write incorrect code. This is why utilizing a version control system like GithHub rarely results in a "Dog Ate My Homework" incident.

Naturally, to utilize GitHub to its greatest potential, you must always make sure to commit and document changes. Beyond this extremely fundamental knowledge, there is so much more you can learn from GitHub.