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.
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.
Push Branch to Another Branch In some cases, you may want to push your changes to another branch on the remote repository. In order to push your branch to another remote branch, use the “git push” command and specify the remote name, the name of your local branch as the name of the remote branch.
To push the commit from the local repo to your remote repositories, run git push -u remote-name branch-name where remote-name is the nickname the local repo uses for the remote repositories and branch-name is the name of the branch to push to the repository. You only have to use the -u option the first time you push.
If you want to push to a remote branch with a different name than your local branch, separate the local and remote names with a colon: git push origin local-name:remote-name .
Actually, Git does not allow creating a (new, isolated) branch on a remote repository. Instead, you can push an existing local branch and thereby publish it on a remote repository.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With