Introduction to Git and GitHub

In this tutorial, we'll see what Git and GitHub are and what they are used for. Personally, I think having these concepts clear is essential in our day-to-day life, whether at work or when we are studying.

 

1 - What is Git?

Git is a version control system. From a developer's perspective, it's a system that stores and manages the changes to the files we modify.

Also, Git is a distributed version system, which means we have a remote repository on the server and a local repository stored on each developer's machine. This means the code is present both on the server and on every machine that modifies it.

It's important to include all of this information, as the vast majority of companies use a version control system, commonly Git, although there are others like Subversion or CSV.

 

1.1 - What is Git for?

In a real work environment, it allows us to work in parallel with several developers. Thanks to Git, we can keep track of all code changes, as well as conflicts.

When we make a change, we say we're making a commit, which contains information like the author, date, a comment, and the files that have changed.

This is an example of several commits I have in a library:

commit github

1.2 - Download Git

If you have Visual Studio 2019 installed, you'll have Git installed on your machine by default, but even so, you can check if it's installed with the following command in the terminal (cmd)

git --version

This will indicate if Git is installed. If not, you can download it from the official site for any version you need

https://git-scm.com/downloads

 

 

2 - What is GitHub?

It's a service for sharing and publishing code. Basically, it's like a social network for programmers, and it uses git behind the scenes.

We will typically work with both Git and GitHub at the same time. Personally, I think it's the best combination. If for some reason you don't like GitHub's interface, you can always use others like Bitbucket.

 

2.1 - Create an account on GitHub

To create a GitHub account, just go to their website

https://github.com/

This way, you can create your first repository.

 

2.2 - What is a repository?

Within GitHub, the code is divided by section, for example, an app to upload images, an app to write posts, etc. Each of these applications is inside a repository, and of course a repository can have more than one application.

Repositories are usually divided internally by business logic.

 

2.3 - Create a repository

To create a repository, you just have to click the green button and you'll start working with it.

crear cuenta repositorio

Enter a name and click create repository.

Additionally, it allows you to specify several things, such as:

If you want the repo to be public or private

If you want to add a README file. README files are usually written in markdown.

Specify the .gitignore file, which will prevent you from publishing files you don't want to be published. Usually, we put all temporary files inside this, such as those in the /bin or /obj folders.

crear repositorio github

2.4 - Use Git on our computer

For that, we'll have to bring the repository to our computer.

As we've mentioned before, in GitHub we have a copy on the server and a local copy. To copy the directory, click the button that says "clone or download" and then click the icon to copy.

clonar un repositorio github

Then, open Visual Studio and click on clone or checkout code

Clonar repostorio vs

And paste the URL in the location field, as you see—you can change it or leave the default.

 clone repo vs

You can use the following command

git clone [email protected]:<tuCuentadeGithub>/ejemploGitHun.git

Now the repository is linked on your computer. So we move on to creating a file or a project, or whatever you want—it also works with audio files, images, etc. It's a version control system for every type of file.

 

 

3 - Make changes

When we make a change—whether modifying a file, adding a file, deleting a file, or moving it—this change will be recorded in the version controller.

That's why we create a plain text file (we can use the README) and add text to it.

As you can imagine, those changes are pending to be sent to the server; to do that you have to perform two steps.

 

3.1 - Make a commit

*Note: In the video, all steps are performed in the graphical interface of Visual Studio. Here in the post, we will use command line.

The first step is to make a commit, which is a command that tells the version server that this version of the file is the current version.

To do this, using the command line or PowerShell, go to the folder where the file is and type the following:

git commit -m “mensaje descripción”

As you can see, the command contains git commit and the -m option, which allows you to write a comment. It is advisable, and should be mandatory, to add a comment when making a commit, so you can quickly see what the change is about.

 

3.2 - Make a push

As we've indicated, the change is in your machine's version controller, but to move it to the server you have to do a push with the following command.

git push

With this, the changes will be moved to the server. If another developer has made any changes while you were working on that file, when you run push Git will indicate there's a conflict and you'll have to resolve it. But we'll see that in the next post.

 

3.3 - Incorporate changes from others

Suppose you went on vacation, and someone started fixing issues in your project during that time. That means your machine has an older version than the real version of the application.

What you need to do now is update the version on your machine.

For this, run the following two commands:

git fechgit merge

These will update your application with the latest changes.

Another option is to do both in a single command:

git pull

but there could be conflicts; the safest is to run both git fetch and git merge.

 

 

This post was translated from Spanish. You can see the original one here.
If there is any problem you can add a comment bellow or contact me in the website's contact form

© copyright 2025 NetMentor | Todos los derechos reservados | RSS Feed

Buy me a coffee Invitame a un café