Git : Push to different remote branch
git, github
Solution
Git is distributed and works locally for most of its operations; it doesn't matter whether the remote exists when you make your branches or commits locally. It just has to exist when you make the push.
So you can add the remote repository, and then push your branch to it. The branch will get created remotely if it doesn't exist.
git remote add github-repo https://github.com/myaccountname/project.git
git push github-repo issue_fix
Problem
Problem: Need to push the changes from local git branch to a different remote git repository branch and this changes pushed to the branch will be compared with the master existing in the remote URL and changes will get merged. Steps I have followed so far create a local git repository, Initialized a simple local git repo using below using commands like below, ``` git init ``` Added existing files to the repo and get them added to the staging area using the below command, ``` MacBook-Pro: $ git add *.h MacBook-Pro: $ git add *.m ``` Checked the status using below command, ``` MacBook-Pro: $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: test.h # new file: test.m # ``` Committed them, ``` git commit -m"Added test base files" ``` Now created a new branch named issue_fix, ``` MacBook-Pro:$ git branch issue_fix ``` Started working on the branch by checking out the branch. ``` MacBook-Pro: $ git checkout issue_fix ``` Made few commits to the branch. Everything was fine up to this. Now I'm in a situation where, I need to push the changes I made to my 'issue_fix' branch to a remote repository URL like this ``` https://github.com/myaccountname/project.git ``` My Changes will get pushed to the branch name given to me or if the branch was not available I need to create a remote branch and push my changes in the local branch to that one. Most importantly pushed changes will be compared with the master in the given repository URL and if everything is fine it will get merged with the master. So I will be always pushing my changes from local to remote branch only. Problem occurred because Clone URL was not given when I started on this, only the source was provided so I created a local git repository and started working on that now the repository URL has been provided and asked to push my changes to a branch. I would like to know, is this possible in the first case?.If possible, give me the commands I need to give to get it working.