Curso de GIT y GITHUB desde CERO para PRINCIPIANTES

4 min read 6 months ago
Published on Aug 17, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

This tutorial serves as a comprehensive guide to Git and GitHub, essential tools for software development. Designed for beginners, it will walk you through the fundamental concepts and commands needed to start using these tools effectively. By the end of this tutorial, you will have a solid understanding of version control, how to manage your projects, and collaborate with others on GitHub.

Step 1: Understanding Git

  • Git is a version control system that helps track changes in files and coordinate work among multiple people.
  • It allows you to manage your project’s history and revert to previous states if necessary.
  • Key benefits include:
    • Easy collaboration
    • Version tracking
    • Branch management

Step 2: History of Git

  • Git was created by Linus Torvalds in 2005 for Linux kernel development.
  • It was designed to handle large projects with speed and efficiency.
  • Understanding its history helps appreciate its capabilities and design choices.

Step 3: Installing Git

  • Download Git from the official website: Git Downloads.
  • Follow the installation instructions specific to your operating system (Windows, macOS, Linux).
  • Verify the installation by running the following command in your terminal:
    git --version
    

Step 4: Basic Terminal Commands

  • Familiarize yourself with terminal commands as they are essential for using Git.
  • Key commands include:
    • cd - Change directory
    • ls - List files in a directory
    • mkdir - Create a new directory

Step 5: Configuring Git

  • Set up your Git identity with the following commands:
    git config --global user.name "Your Name"
    git config --global user.email "you@example.com"
    
  • This configuration helps associate your commits with your identity.

Step 6: Initializing a Repository

  • Create a new Git repository using:
    git init
    
  • This command sets up a new directory for version control.

Step 7: Working with Branches

  • Branches allow you to work on features independently without affecting the main codebase.
  • Create a new branch using:
    git branch branch-name
    
  • Switch to the new branch with:
    git checkout branch-name
    

Step 8: Staging and Committing Changes

  • Stage changes with:
    git add filename
    
  • Commit your changes with a descriptive message:
    git commit -m "Your commit message"
    

Step 9: Viewing Logs and Status

  • Check your commit history using:
    git log
    
  • Check the status of your repository with:
    git status
    

Step 10: Checking Out and Resetting Changes

  • To switch branches or restore files:
    git checkout branch-name
    
  • To reset changes in your working directory:
    git reset --hard
    

Step 11: Setting Up .gitignore

  • Create a .gitignore file to specify files and directories Git should ignore.
  • Typical entries include:
    • node_modules/
    • *.log

Step 12: Using Git Diff

  • Check for changes between your working directory and the last commit:
    git diff
    

Step 13: Navigating Branches

  • Move between branches using:
    git switch branch-name
    

Step 14: Merging Branches

  • Merge changes from one branch into another:
    git merge branch-name
    

Step 15: Conflict Resolution

  • Learn to resolve merge conflicts by editing the conflicting files and committing the resolved changes.

Step 16: Using Git Stash

  • Temporarily store changes that you aren’t ready to commit:
    git stash
    

Step 17: Introduction to GitHub

  • GitHub is a platform for hosting Git repositories online, facilitating collaboration and project management.

Step 18: Creating a GitHub Repository

  • Create a new repository on GitHub and follow the instructions to connect your local repository.

Step 19: Pushing to GitHub

  • Upload your local changes to GitHub:
    git push origin main
    

Step 20: Collaborating on GitHub

  • Learn about forking, pull requests, and collaborative workflows to work effectively with others.

Conclusion

By following these steps, you should have a foundational understanding of Git and GitHub. Practice using the commands and concepts introduced in this tutorial to solidify your skills. As you advance, consider exploring more complex features like GitFlow, cherry-picking, and GitHub Actions. Happy coding!