Setting up Git for the first time

- 👤 Andrés Cruz

🇪🇸 En español

Setting up Git for the first time

If you're a software developer, you've probably heard of version control. This practice is essential for managing changes to your code over time. One of the most popular version control systems is Git, widely used by developers around the world. In this guide, we'll explore how to set up Git for the first time and some tips to get the most out of it.

Git is a fundamental tool when developing our applications, any package today that you want to use or any project that you want to see as a reference probably uses Git to manage its versions and is hosted in a repository on the Internet such as GitHub.

What is Version Control?

Version control is the management of changes to documents, files, or any other type of data. In software development, it is essential to track and manage code changes, ensure code quality, reduce errors, and improve collaboration between team members. Without version control, managing and tracking code changes would be a difficult and error-prone task.

What is Git?

Git is a version control system widely used by developers to manage changes in the code, as we mentioned before, it is widely used with github or similar, since in this way we can have a reference and order when developing our projects, that if we did some development two years ago and we want to review something, we can perfectly see the history in git or do a checkout at the time that change was made to our project and review the change.

In short, git is your best ally for developing applications, there are countless reasons to use it whether you develop in a team or alone, you should always have a copy of your work and log and that is what git is for and much more.

Git Initial Setup

1. Download Git

To get started, download Git from the official Git site. Choose the appropriate version for your operating system.

2. Install Git

Follow the installation instructions for your operating system, but you can go to the official Git page and see what the options are depending on your operating system, usually it is either a console command or simply running an executable.

Once installed, verify that Git is available on the command line by running:

git --version

It should return a number that indicates the version of git installed on your computer.

3. Set your Name and Email

Set your name and email address so Git can identify your changes correctly:

git config --global user.name "Your Name"

git config --global user.email "your@email.com"

This is essential if you later want to use a system like github to store your work.

4. Create a Repository

Finally, with the previous steps you can now use git, the first thing we do is initialize a project, whether it is empty or not, there are no excuses to start a new project in git.

  • New Repository:
    • Create a folder for your project and run:

      git init
  • Clone Existing Repository:
    • Run:

      git clone <URL del Repositorio>

Basic Git Commands

Git has an infinite number of commands that you can use, but among the main ones we have the following:

  • git add <file>: Add changes to the staging area.
  • git commit -m "Commit Message": Make a commit with a descriptive message.
  • git push: Push changes to the remote repository.
  • git pull: Get changes from the remote repository.

Good Practices with Git

  • Atomic Commits: Make small, specific commits.
  • Write Descriptive Messages: Clearly describe the changes made in each commit.
  • Use Branches: Create branches for new features and fix bugs in the main branch.
  • Collaborate: Work with other developers and use tools like GitHub or GitLab.

How to Save Username and Password in Git

Credential management in Git is crucial to facilitate the workflow and ensure the security of your repositories. In this guide, we'll explore how to save your Git username and password securely.

1. Initial Configuration

Before you begin, make sure you have Git installed on your system. Then, follow these steps:

  1. Set your Name and Email:
    • Open a terminal and run the following commands:

      git config --global user.name "Your Name"
      git config --global user.email "your@email.com"
    • Replace “Your Name” and “your@email.com” with your real information.
  2. Save your Credentials:
    • Run:

      git config --global credential.helper store
    • This will store your credentials in a file on your local drive.

2. Security Considerations

It is important to keep the following in mind:

  • Plain Text Storage: Credentials are saved in a plain text file on your computer. Make sure no one else has access to this file.
  • Safer Alternatives:
    • If you want a more secure solution, consider using SSH or personal access tokens instead of saving passwords in plain text.
    • You can configure Git to use OAuth authentication using Git Credential Manager.

3. Test and Document

  • Test your Configuration: Perform some Git operations (such as pull or push) to verify that your credentials are saved correctly.
  • Document your Changes: Add comments in your code or in a README file to explain how you set up your credentials. This will be useful for you and other developers working on the project.

How to Save Username and Password in Git

Credential management in Git is crucial to facilitate the workflow and ensure the security of your repositories. In this guide, we'll explore how to save your Git username and password securely.

1. Initial Configuration

Before you begin, make sure you have Git installed on your system. Then, follow these steps:

  1. Set your Name and Email:
    • Open a terminal and run the following commands:

      git config --global user.name "Your Name"
      git config --global user.email "your@email.com"
    • Replace “Your Name” and “your@email.com” with your real information.
  2. Save your Credentials:
    • Run:

      git config --global credential.helper store
    • This will store your credentials in a file on your local drive.

2. Security Considerations

It is important to keep the following in mind:

  • Plain Text Storage: Credentials are saved in a plain text file on your computer. Make sure no one else has access to this file.
  • Safer Alternatives:
    • If you want a more secure solution, consider using SSH or personal access tokens instead of saving passwords in plain text.
    • You can configure Git to use OAuth authentication using Git Credential Manager.

3. Test and Document

  • Test your Configuration: Perform some Git operations (such as pull or push) to verify that your credentials are saved correctly.
  • Document your Changes: Add comments in your code or in a README file to explain how you set up your credentials. This will be useful for you and other developers working on the project.

 

I agree to receive announcements of interest about this Blog.

Git, the widely used version control system, is essential for tracking and managing code changes. Learn how to set it up for the first time.

| 👤 Andrés Cruz

🇪🇸 En español