Welcome to the Git Local Protocol tutorial! In this lesson, we'll guide you through the basics of Git, a powerful tool for version control. By the end, you'll be able to manage your code like a pro. Let's dive in! 💦
Git is a distributed version control system that helps you manage your code changes. It enables collaboration, backup, and recovery for your projects. Think of it as a time machine for your code!
Before we dive into Git commands, let's get it installed. Visit the official Git website and download the version suitable for your operating system. Follow the installation instructions, and you're ready to go!
Once installed, open your terminal (Command Prompt on Windows, Terminal on macOS or Linux). To start using Git, you'll need to set up your account information and configure your settings:
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"Replace "Your Name" and "your.email@example.com" with your actual name and email address.
To start using Git on your project, navigate to your project folder and run:
git initThis command initializes a new Git repository in your project folder.
Git tracks changes in files that are added to the .gitignore file, which lists the files to be ignored. If you don't have one, create it using the following template:
# Ignore generated files
node_modules
.vscode
.idea
.git
To add files to the Git repository, use:
git add .This command stages your files, making them ready to be committed.
A commit is a snapshot of your project at a specific point in time. To create a commit, use:
git commit -m "Your commit message"Replace "Your commit message" with a brief description of the changes you've made.
To see your commit history, use:
git logThis command displays the list of commits, showing the commit message, author, and date.
A branch is a separate line of development, allowing you to work on different features without affecting the main project. To create a new branch, use:
git branch new-branch
git checkout new-branchTo merge your new branch back into the main branch, use:
git checkout main
git merge new-branchConflicts may occur when changes are made to the same file in different branches. In such cases, you'll need to resolve the conflict manually.
Remote repositories allow collaboration and backing up your code on platforms like GitHub, Bitbucket, and GitLab. To add a remote repository, use:
git remote add origin https://github.com/yourusername/your-repository.gitReplace "yourusername" and "your-repository" with your GitHub username and the name of your repository.
To push your local repository to a remote repository, use:
git push -u origin mainThis command pushes the local main branch to the remote repository.
With that, you've mastered the basics of Git for local protocol. Happy coding! 💡🚀