Git command to push the files without cloning

Viewed 43

I have a requirement,

  1. I need to clone a remote branch to Local.
  2. Add some files the local folder
  3. Push the changes to some other existing remote branch.

But, when I do got push, it is actually cloning the remote branch details in to my local, and then pushing it. Because of that, I am losing the newly added files in my local (those will be overwrite) and those files will not push to the other branch.

The command I am using to push is as below:

git init  
cd git_test
git fetch
git checkout repobranchB
git add -A
git commit -m "test"
git push 

Is there any option in git push, where it will not clone the existing files in the remote branch to local? I just need to add all the files in my local to the specified remote branch.

1 Answers

It sounds like you want to:

  1. Checkout the branch
  2. Pull remote changes (temporarily)
  3. Make YOUR changes to the files
  4. Commit and push to remote
  5. Checkout your old branch again locally

You can even delete the local branch if you no longer need it:

git branch -d repobranchB

Commits on one branch should not effect another unless you 'git add...' the changes while on that branch. When you switch back to the original branch your changes won't be there

https://git-scm.com/book/id/v2/Git-Branching-Remote-Branches

Related