Home > database >  How to clone single branch from one repo to empty new repo?
How to clone single branch from one repo to empty new repo?

Time:09-20

How to clone one single branch from repository 'A' to other new repo 'B' in azure?

I've cloned the repo 'B' in VS Code, it is empty, so there is one branch only which is main then I opened repo 'A', branch I want to clone then copied HTTPS link.

In VS Code terminal I used 'git clone --single-branch --branch 'name' 'link'. I am able to run the project locally, but I am not able to push it back to azure.

CodePudding user response:

I'm not sure is there any shortcut to do that, but you always can push specific branch to another remote that you've just cloned.

  1. Firstly you have to add the azure remote that you mention by this command git remote add [name of the remote] [git address of the remote]

  2. Push specific branch to that remote by this command git push -u [name of the remote] [name of the branch you wanna push]

for example:

  1. git remote add azure https://azure.git
  2. git push -u newbranch azure

CodePudding user response:

One way to achieve this by creating a new branch and making a pull request on Azure.

  1. In your GIT cmd, type

git checkout -b new-branch-name

  1. Then add all the changes you want to push, type

git add .

  1. and then

git commit -m "message"

  1. lastly push the changes by typing

git push origin new-branch-name

After pushing the changes, you may get prompt for entering git credentials, do that. after entering credentials, on your Azure git, you will see a button "Create Pull Request". I hope you can do the rest by yourself. For any help, please comment.

  •  Tags:  
  • git
  • Related