Ans- To switch back to the main branch (often called `master` or `main`) using Git, follow these steps:
1. Open your terminal or command prompt and navigate to the root directory of your Git repository.
2. Check the list of existing branches and identify the main branch by running the command `git branch`. The currently checked out branch will be highlighted with an asterisk (`*`).
3. Switch to the main branch using the command `git checkout main`. Replace `main` with the name of your main branch (`master` or `main` depending on your repository setup).
For example:
$ git checkout main
Switched to branch 'main'
Alternatively, you can use the full command `git switch main` to achieve the same result.
$ git switch main
Switched to branch 'main'
4. After running the `git checkout` or `git switch` command, you will be switched to the main branch. Now you can continue working on this branch and make changes specific to it.
Remember to commit any changes you made on the previous branch before switching branches to avoid losing your work. Switching branches discards any uncommitted changes that are not yet staged or committed.
Make sure to push your changes to the remote repository using `git push` if you want to update the main branch on the remote repository.
Here's an example of the commands:
$ git branch
* feature
main
$ git checkout main
Switched to branch 'main'
In this example, the `feature` branch is currently checked out. We run `git checkout main` to switch back to the main branch. Git then confirms the switch and notifies that we are now on the `main` branch.
Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.
We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc