Git and GitHub
Tags: javascript, github, git, programming
Published: 2022-11-27 21:12:34

Programmers are always writing codes, either to add a new feature to an already existing code, or writing a new one.

Our source code can grow big fast. Also, as developers, we at some point work with other developers or need to study and update another's code, so we always need a way of tracking the changes we make in our codebase.

There are many ways and systems to track changes in our codebase, but in this short writeup, we will look at one of them, Git.


![Version control meme](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7b60m0r1omen05gyk1lg.jpg)

## GIT

Git is a distributed version control system, used in tracking changes in any set of files, usually used for coordinating work among programmers collaboratively developing source code during software development.

To get started with git, first, you will need to install Git on your system.

[](https://git-scm.com/downloads)

After installation, typing this command on your terminal will let you know if Git was successfully installed. If so, you will be able to see the current version of Git running in your system.

`git --version`

```
C:\Users\MyPC>git --version
git version 2.35.1.windows.2
```

### Setting things up:
The first thing you will probably do is let Git know who you are. This will enable Git to determine who makes what changes in our code and the changes made.
To do this, you will need to set your username and email like this...

```
git config --global user.name "[firstname lastname]"
git config --global user.email "[valid email]"
```

### Working with Git:
To get started with git, navigate to your fill folder using your terminal and type the following command; This will initialize a new git repository for your codebase.

`git init`

There are lots of commands we use while working with git, let's see some of them.

The `git add [filename]` command allows you to add a file to the staging area. With `git add .`, you can add all the files at once.

`git commit -m "[commit message]"`: The git commit command is used to move files from the staging area to your local repository. This command comes after the 'git add' command.

`git status` command shows the state of your working directory and helps you see all the files which are untracked by Git, staged, or unstaged.

`git branch <branch name>": The git branch command allows you to create, list, rename and delete branches. Many operations on branches are applied by **git checkout** and **git merge** commands.

`git push <remote> <branch>`: The git push command is used to upload local repository content to a remote repository (e.g GitHub). Pushing is how you transfer commits from your local repository to a remote repo. It's the counterpart to **git fetch**, but whereas fetching imports commits to local branches, pushing exports commits to remote branches.

---

## GitHub

GitHub is an Internet hosting service for software development and version control using Git. It provides the distributed version control of Git plus access control, bug tracking, software feature requests, task management, continuous integration, and wikis for every project.


To get started with GitHub, you will need to create an account on their website [](https://github.com/).

GitHub allows us the flexibility of managing our code in a nice graphical interface.

#### Repository
A repository (abbreviated as repo) is a location where all our files for a particular project are stored. You can easily create a new repository on your GitHub page either by clicking the 'New repo' button or clicking on "New repository" on the plus icon from the navigation. Each repository can be accessed through a unique URL.


![An example of creating a new repo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9s2p8d5m1bednz9ikril.png)

#### Forking
“Forking” is when you create a new project based on another project that already exists. This is an amazing feature that vastly encourages the further development of programs and other projects. If you find a project on GitHub that you’d like to contribute to, you can fork the repo, make the changes you’d like, and release the revised project as a new repo. If the original repository that you forked to create your new project gets updated, you can easily add those updates to your current fork.

#### Pull Requests
You’ve forked a repository, made a great revision to the project, and want it to be recognized by the original developers—maybe even included in the official project/repository. You can do so by creating a pull request. The authors of the original repository can see your work, and then choose whether or not to accept it into the official project. Whenever you issue a pull request, GitHub provides a perfect medium for you and the main project’s maintainer to communicate.

#### Social Networking
The social networking aspect of GitHub is probably its most powerful feature, allowing projects to grow more than just about any of the other features offered. Each user on GitHub has their own profile that acts like a resume of sorts, showing your past work and contributions to other projects via pull requests.

Project revisions can be discussed publicly, so a mass of experts can contribute knowledge and collaborate to advance a project forward.