简体   繁体   中英

How can I clone a specific branch and push changes to this branch only in GIT

How can I clone a specific branch and push changes to this branch only in GIT. I know how to clone a specific branch but not sure to how to push to this branch only. As there is no chance of mistake so if someone can mention the series of step that will be great. To clone repository, I tried below.

git clone -b <branch_name> <url>

clone a specific branch

git clone -b <branch> <remote_repo>

push to specific Git branc

git checkout YourBranch
git push origin YourBranch

Clone only your specific branch

git clone -b <Your_Branch> <URL of git_repo>

Check you are in correct branch

git branch -a

output will be like below

*Your_Branch
remotes/origin/master

* mark will tell in which branch you are in.Now go inside the cloned repository and run git commands to push your changes to git.

cd git_repo
git add *
git commit -m "Did changes/added new files"
git push

Above will push files into Your_branch only.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM