Search code examples
gitgit-clone

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>

Solution

  • 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.