GIT; VersioN ControL SysteM
Tags: beginners, github, git, devjournal
Published: 2021-11-30 10:36:27


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/748mgznsk4z19t0ul9sf.jpg)Imagine in a scenario where there wasnt any github. What were developers using to collaborate with? It goes wth doubt that most people think that the only version control system available is github.Am i wrong? What is a version control system? 

Welcome to my first technical based blog....

A version control system is a category of software tools that helps in recording changes made to files by keeping a track of modifications done to the code. These changes maybe include removing or adding lines of code to the source code between a group of developers in disregard of their geographical location. If a mistake is made developers can turn back the clock and compare earlier versions of the code to help fix the mistake while minimizing disruption to all team members.

The first Version Control System was created in 1972 at Bell Labs where they developed UNIX. The first one was called SCCS. It was available only for UNIX and only worked with Source Code files. Both SCCS and RCS only worked on the development system and were not for sharing code, as they only worked for a single user.Verson cotrol system has two types central and dstrubuted system dfferentated by the number of repostores each has. Examples of version control systems are Git, hackmoon, apache, mecurial, AWS code commit among others. 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/osbz86781cjzoztgdlhs.jpeg)

Git will be the main version control system focus for now. Git is a version control system that lets you manage and keep track of your source code history. While there are some great git GUIs (graphical user interfaces), it's easier to learn git using git-specific commands first and then to try out a git GUI once you're more comfortable with the command.
The steps to being comfortable working with git are:

- Install git and Create a github account
Git and github are different in that git is open-source, version control tool while github uses git to integration 

- Cloning a Repository
This one is simple in itself. You just created a repository and you want to clone it on your machine. Just run:
git clone <REPOSITORY_GIT_URL>

- Adding a Repository Into an Existing Project
Let's say you already are working on a project and decided later on to create a repository for it. How do you add the repository to it?

```
git init
git add .
git commit -m "Initial Commit"
git remote add origin <REPOSITORY_GIT_URL>

If the repository you are adding is empty, you can just run:

git push origin master
```
If, however, the repository has some files in it, I suggest you run this first:

```
git pull origin master
```
Then run the push command.

- Get Changes from Repository
To get changes from a repository:

```
git pull origin master
Undo Add Command
If you ran:

git add <files>
or

git add .
```
then you realized that you made a mistake and you don't want to actually add those files, just run:

```
git reset <files>
This will undo adding specific files. If you want to undo adding all files:
```

```
git reset
Undo Latest Commit
You made a commit, then realized something is wrong with it. To undo it, simply run:

git reset ~HEAD
```
You can also run:

```
git revert HEAD
```
The difference is that git revert will add a new commit that reverts the latest commit. It's probably more helpful if you've pushed the commit that you want to undo.

- Edit Latest Commit
To edit the last commit or the last commit message, run:

```
git commit --amend -m "new message"
```

- Remove Local Changes
If you made changes locally and you don't want them anymore for one reason or another, you can revert them back to their latest version in your Git Repository by running:

```
git checkout .
```
To remove local changes of specific files instead of all changes you can run:

```
git checkout <files>
```

- Create a Branch
To create a new branch:

```
git branch <NEW_BRANCH>
```

- Switch Branches
To switch from one branch to another:

```
git checkout <BRANCH_NAME>
```
Create a New Branch And Switch To It
To create a new branch and switch to it immediately, you can run:

```
git checkout -b <BRANCH_NAME>
```

- Delete a Branch
To delete a branch:

```
git branch -d <BRANCH_NAME>
```

- Merge Branches
To merge a branch to another, switch to the branch you want to merge to then run:

```
git merge <BRANCH_NAME>
```
"Stash" Your Local Changes
Sometimes you might have changes locally, but you are not ready to commit them. If you need to work on something else in the meantime, go back to the original state of the repository, or change branches without losing changes, you can "stash" those changes for later:

```
git stash
```
Then, when you want to pull out those changes again, just run:

```
git stash pop
```
Running this command will apply the latest changes you put in the stash and then remove it from the stash.

If you have a lot of changes that you've "stashed", you can check them by running:

```
git stash list
```
Then, you can apply a stash from the list:

```
git stash apply <STASH_NAME>
```
Set Your Email and Name In The Configurations
You can do this on a global scope and on a repository's scope. These commands will work on a global scope just by adding the --global option.

- To set the email:

```
git config user.email "YOUR_EMAIL"
```
To set the name:

```
git config user.name "YOUR_NAME"
```

- Remove Files From a Git Repository
To remove files from a Git Repository:

```
git rm <files>
```
To remove those files only from Git without removing them locally:

```
git rm --cached <files>
```
To remove directories just add the -r option.