DEV Community

Cover image for Git and GitHub
Lucas Saladini
Lucas Saladini

Posted on

Git and GitHub

To perform the code versioning from a code base that is used in a system or in a personal project, typically, the developers use GitHub to store the repositories and allow a collaborative development.

There are two types of version control forms:

  • CVCS
  • DCVS

CVCS are centralized version control, and we can cited CVS and Subversion as examples; DVCS are decentralized version control like Git and Mercurial.

Taking into consideration that GitHub is widely used and free, this makes the platform the most preferred by the developers that are beginning their career, but, before we start using GitHub, we need to take a step back and do some configurations before we can use the repository locally.

We need to have an account in GitHub so we can proceed with the configurations, if you do not have an account, click here to create one.
After creating an account, you need to install Git on your machine, if you do not have Git installed, click here to install.
Having completed all the steps prior, you need to globally config your username and email, to do so, you need to run the following command line on your terminal or on the Git Bash:

git config --global user.name

After setting up your username (it's highly recommended that you use the same email that you use to access your GitHub account), it's time to set your email using the following command line:

git config --global user.email

Nowadays, GitHub sets your branch as main, but, if, for some reason, your branch name is master, you can (and probably should) change its name for main, to do so, you need to run the following command line, changing by main:

git config init.defaultBranch <branch_name>

If you have a local repository that is not on GitHub, you will need to run two command lines, being the first one to initiate git and the second one to add to GitHub:

git init
git remote add origin <repository_url>

After all these steps, you can start working with GitHub locally and send the modifications to the platform.

Every time a file is modified or created, you will need to add it to go to the staging area and, to do so, you will need to run the following command line:

git add . (to add all)
git add <file_path/file_name.extension (to add a specific file)

After adding all files it is necessary to commit them, making them ready to be sent. You can do this using the following command line:

git commit -m "Message that you want to use (describe what you done)"

If you need to correct the message, you can run the following:
git commit --amend -m "New message"

After adding and commit the modifications/additions, it is time to send the files:
git push origin <branch_name>

Top comments (0)