🧑💻 New to Git or LabEx? We recommend starting with the Quick Start with Git course.
When working with Git, it's common to have multiple branches in a repository. However, it can be difficult to keep track of all the branches and their last commit dates. In this challenge, you will learn how to use Git to sort branches by date, making it easier to manage your repository.
You have a Git repository with multiple branches, and you want to sort them by date. This will allow you to see which branches have been updated recently and which ones have not. Sorting branches by date can also help you identify branches that may need attention or merging.
Tasks
For this challenge, let's use the repository from https://github.com/labex-labs/git-playground.
Clone the repository, navigate to the directory and configure the identity.
Create a branch called one, create a file named hello.txt and commit it with the commit message "hello.txt".
Switch to the branch named master and create a branch named two.
Now, sort the branches by date.
This will display a list of all local branches and sort them based on the date of their last commit. You can use the arrow keys to navigate the list, and press Q to exit.
This is the finished result:
Summary
Sorting Git branches by date can be a useful tool for managing your repository. By using the git branch --sort=-committerdate command, you can easily see which branches have been updated recently and which ones may need attention. This challenge has provided you with the knowledge and skills to sort Git branches by date, making it easier to manage your repository.
We use cookies for a number of reasons, such as keeping the website reliable and secure, to improve your experience on our website and to see how you interact with it. By accepting, you agree to our use of such cookies. Privacy Policy