DEV Community

Cover image for Dude, do the initial Git configuration
Julio Santacruz
Julio Santacruz

Posted on

Dude, do the initial Git configuration

Intro

Hello, Let me tell you that I just restarted my work computer, why is this relevant? because I lost all my settings and it's time to configure them again. I imagine you got an idea with the title, we will see the initial git configurations, the ones I need to start working.

I hope this publication is useful to you, I am sure it will be useful for my future self.

what is Git?

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. there is more software for version control, but git is the one I like to use.

Initial Configuration

First of all, to start a new repository we can use the command

git init
Enter fullscreen mode Exit fullscreen mode

Now let's set the user information (us).

git config --global user.email "your@email.com"
git config --global user.name "your_name"
Enter fullscreen mode Exit fullscreen mode

To find where the settings are stored we can use the command.

git config --list --show-origin
Enter fullscreen mode Exit fullscreen mode

Git works with branches, I'm sure you already know that, as I write this, the default name of the main branch is 'master'. By convention we could call it 'main', let's see how to change the name

git branch -m old_name new_name
Enter fullscreen mode Exit fullscreen mode

to ensure that all projects start with the main branch name 'main'

git config --global init.defaultBranch main
Enter fullscreen mode Exit fullscreen mode

BONUS

For bonus we are going to connect our project to a repository in GITHUB. As a first step we are going to set the 'origin'

git remote add origin repository_URL
Enter fullscreen mode Exit fullscreen mode

To verify that the URL was saved correctly

git remote -v
Enter fullscreen mode Exit fullscreen mode

To fetch the latest version from the remote repository

git pull origin main
Enter fullscreen mode Exit fullscreen mode

if there is an error for different versions we can add the flag '---allow-unrelated-histories'

git pull origin main --allow-unrelated-histories
Enter fullscreen mode Exit fullscreen mode

Finally, to send our information to the remote repository we can do git push and save the changes from our local repository to GitHub

git push origin main
Enter fullscreen mode Exit fullscreen mode

Top comments (0)