GIT
Understanding Repositories
In this chapter, we will focus on how to create and manage Git repositories. A repository is the place where Git stores the complete history of changes made to a project. These repositories can be on your local machine or on a cloud platform like GitHub. By the end of this chapter, you will know how to create local repositories, how to clone them, and how to manage changes in them.
Local Repositories vs Remote Repositories
Local Repositories
A local repository is one that resides on your computer. You can create local repositories to work on your personal projects without needing to be connected to the Internet. All the changes you make will be saved locally and will only be reflected on your machine.
To create a local repository, use the following command:
bash
Once you've initialized your repository, you can start adding files and making commits.
bash
Remote Repositories
A remote repository is a version of the repository that is stored on a remote server. Remote repositories allow you to collaborate with other developers, keep backups of your work, and access the repository from anywhere.
Platforms like GitHub, GitLab, and Bitbucket are examples of services that offer remote repositories.
To connect a local repository with a remote one, use the following command:
bash
Cloning Repositories
Cloning a repository is basically copying a remote repository to your local machine. This is useful when you want to work on a project that already exists or when you need to collaborate on other people's projects.
bash
Once you have cloned a repository, you can start making changes and synchronize them with the remote repository.
Navigating and Viewing Repository Status
One of the main advantages of Git is the ability to review the change history and the current state of your project at any time. Below, we will look at some of the most common commands to view the repository status.
Viewing Repository Status
The git status
command is one of the most used to check the current status of the files in the repository. This command shows you which files have been modified, which are in the staging area, and if there are any new or untracked files.
bash
Viewing the Change History
To review the history of commits made in the repository, you can use the git log
command. This command shows you a list of all commits, including the author, date, and commit message.
bash
This history is essential for tracking changes and understanding the evolution of a project.
Conclusion
In this chapter, we have learned how to create local and remote repositories, and how to clone repositories to work on them locally. We have also seen how to navigate and view the status and history of a repository to maintain proper project control. In the next chapter, we will explore the basic workflow in Git, from adding changes to making commits and working with branches.
- Introduction to Git and Version Control
- Installation of Git and Initial Setup
- Understanding Repositories
- Basic Workflow in Git
- Working with Branches in Git
- Collaborating with Other Developers
- Undoing Changes in Git
- Working with Tags in Git
- Rebase and Squash in Git
- Stashing and Cleaning in Git
- Advanced Git Commands
- Hooks and Automation in Git
- GitHub and Repository Management
- Best Practices in Git
- Conclusion and Final Tips