DEV Community

mibii
mibii

Posted on • Edited on

Git you can learn on the fly

Git is a tool that you can learn on the fly, so there's no need to dedicate extensive time to mastering it. For anyone already familiar with using the Command Line Interface (CLI), I'd say a day is more than enough to get a good grasp of the basics. While a Windows version of Git is available, the CLI in many cases, offers a more streamlined and efficient workflow.

Git is a powerful tool for version control in programming projects, allowing developers to efficiently collaborate, track, and make changes to code.

Consider understanding the Git as a time machine that let you travel back to previous version of your files (reality) or even create an alternate (parallels version of reality).

Git allows you to navigate through the history of your project, enabling you to revisit previous versions of your files as if traveling back in time. Additionally, Git empowers you to create branches and parallel versions of reality, where you can experiment, test new features, and diverge from the main line of development without affecting the main project. This flexibility and control over the project's timeline make Git a valuable tool for developers to manage and explore different paths in their projects, much like a time traveler exploring alternate realities. Git provides a robust backup mechanism for your codebase, allowing you to recover previous versions and undo changes easily.

Understand the difference - the git itself and the GitHub.

Git operates locally on a developer's machine, enabling them to create repositories, track changes, commit code, create branches, merge changes, and revert to previous versions.
GitHub is a web-based platform that hosts Git repositories and provides additional collaboration and project management features. GitHub serves as a centralized hub for developers to store, share, and collaborate on Git repositories, offering features such as issue tracking, pull requests, project boards, and wikis.
The Git and the GitHub - it is not a client-server application case. GitHub offer additional collaboration features and centralized code hosting, Git's local capabilities provide a solid foundation for managing code versions, experimenting with new features, and maintaining a clean and organized development workflow entirely on your local machine.

Basic Git commands for beginners:

On your local pc - open your project folder

  1. git init - Initializes a new Git repository in your project. This is the first step to start tracking changes to your project files.

  2. git clone URL - Clones an existing repository to the specified URL. This is useful when you want to start working on an existing project.

  3. git add file - Adds files to the index for subsequent commits. This is necessary for Git to start tracking changes to these files.

  4. git commit -m "Commit message" - Commits changes to the repository with a specific message describing the essence of the changes.

  5. *git push *- Push local commits to a remote repository, making your changes available to other project members.

  6. git pull - Gets changes from a remote repository and merges them into your local version of the project.

Real example of using Git:

Let's imagine that you are working on a website project and want to add new functionality. Here's how you can use Git to manage this process:

  • Create a new branch: First, create a new branch to develop your functionality:
git checkout -b feature/new-feature
Enter fullscreen mode Exit fullscreen mode
  • Development: You make changes to the code, adding new functionality.

  • Adding Changes: Once you're done, add the changed files to the Git index:

git add .
Enter fullscreen mode Exit fullscreen mode
  • Commit changes: Commit your changes to the repository with a clear message:
git commit -m "New functionality added"
Enter fullscreen mode Exit fullscreen mode
  • Submitting changes: Submit your changes to the main repository:
git push origin feature/new-feature
Enter fullscreen mode Exit fullscreen mode
  • Create a Pull Request: Visit the Git repository hosting platform (e.g., GitHub, GitLab) in your browser, navigate to your branch, and click on the "Create Pull Request" button. Provide a title, description, and select the branches you want to merge.

By following these steps, you can effectively create a Pull Request in Git to propose changes from your branch to the main branch of the repository.

This example demonstrates a basic workflow using Git that allows developers to efficiently collaborate and manage code changes. As you work with Git, you'll discover many other useful commands and strategies for managing your projects.

Top comments (0)