Reputation: 1272
I am working with three forked versions of a source code. FYI I changed the names to not disclose identities/repos. Here is how it is laid out:
MyMBP:~/Documents/_library$ git remote -v
abc https://github.com/abc/_library (fetch)
abc https://github.com/abc/_library (push)
origin https://github.com/123/_library.git (fetch)
origin https://github.com/123/_library.git (push)
upstream https://github.com/source/_library (fetch)
upstream https://github.com/source/_library (push)
Here, upstream is the original source code that is the most up to date and stable version. Origin is my forked version. ABC is someone else's version.
ABC had a branch that I pulled from to work off of. I wanted to then make changes and push up to my repo (origin), and subsequently submit a pull request. The branch on ABC, was called "abc/obs-noise".
Upon git status:
git status
HEAD detached from abc/obs-noise
When I made the changes to said file, I committed:
git commit
[detached HEAD e8eeea3] OBSERVATION NOISE ADDITION TO THE MONITORS
1 file changed, 23 insertions(+), 11 deletions(-)
Then I git pushed (supposedly to my origin).
git push -u origin abc/obs-noise
Counting objects: 5, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 733 bytes | 733.00 KiB/s, done.
Total 5 (delta 4), reused 1 (delta 0)
remote: Resolving deltas: 100% (4/4), completed with 4 local objects.
To https://github.com/123/_library.git
* [new branch] abc/obs-noise -> abc/obs-noise
However, I go to my repo... no abc/obs-noise, or any evidence of this commit. I am a noob at git, but I am almost sure I did everything right and it looks that way. I am wondering where do I find my commit? I would hate to redo all my work.
Upvotes: 15
Views: 17836
Reputation: 41
Hope this will help Someone who face this type of issue:
If you want to push changes from one local branch to a different branch on the remote, here's how you can do it.
git push <remote-name> <local-branch-name>:<remote-branch-name>
If you get an error like:
error: The destination you provided is not a full refname...
This usually happens when the branch name isn't fully specified. Using the full branch names in the command solves this.
Thanks in Advance :)
Upvotes: 2
Reputation: 7063
You can't push from detached HEAD. The only way is
git checkout -b newbranch e8eeea3
git push origin origin_branch_name
For further details see here
Edit after input from @Torek: There might be uses cases, where you want to push a detached head. For details see here. See comment below.
Upvotes: 4
Reputation: 17455
First of all, you are sitting on a detached HEAD. It means that any commit that you have just made will not move the original branch pointer. So you have great chances to lose these commits if you change active branches, and that's why git push doesn't push anything new: original branch pointer hasn't been moved.
First of all, when you start working on any of remote branch you should create a local branch, corresponding to a given remote branch. Use
git checkout -b <local_branch_name> <remote>/<branch>
Then as you make commits, this <local_branch_name>
will advance to follow your commits line. When you need to push a given commit line to a remote branch, use
git push <remote> <local_branch_name>:<remote_branch_name>
If you need to have several development lines for different remotes, you should created several corresponding local branches and push them separately.
Upvotes: 13