When working with repositories in DevOps, managing branches effectively is crucial.
If you’re not working in the main branch and have set up other branches for your repository, you’ll likely need to switch between them while working on your cloned repository.
Let’s say that you have a main branch, and a empty newly created demo branch.
So, how can you do that?
First, ensure that Git is installed on your machine before you start navigating between branches. You can download and install Git here.
Next in your DevOps copy the path of your repository.
After having Git installed, you can use the cmd (command line), in the folder where you want your DevOps repository to be cloned by writing in the folder path: cmd.
This will open a command line where you can now write the git command to clone your repository.
- Clone the repository from Azure DevOps:
git clone https://<PAT>@dev.azure.com/<Organization>/<Project>/_git/<RepositoryName>
- Navigate to the newly cloned repository and on the same command line:
cd <RepositoryName>
- Initialize Git if required (this is usually done automatically):
git init
- Check out the branch where you want to add the files:
git checkout <BranchName>
- Pull the latest changes from the branch to ensure it’s up to date:
git pull origin <BranchName>
- If you have files to add to your repository, here you can add your files to the repository by copying them into the repository folder.
- Stage the changes:
git add .
- Commit the changes with a meaningful message:
git commit -m "Your commit message here"
- Push the changes to the specified branch:
git push origin <BranchName>
And so these are the steps on how you can add your files to a specific repository branch!
But how can you Switch?
Once the connection between your DevOps repository and the branch is set up locally, switching between branches becomes a breeze. All you need to do is use the simple Git command:
git checkout <BranchName>
This command allows you to seamlessly switch between branches, making it easier to work on different features or tasks without any hassle. With Git set up and your branches organized, managing your workflow becomes more efficient and streamlined.
To lazy to read? We’ve got you covered! Check out our video version of this content!
Hope you find this helpful! If you enjoyed the content or found it useful and wish to support our efforts to create more, you can contribute towards purchasing a Star Wars Lego for Sandro’s son!