I'm new to git and I started making changes to a previous commit without creating a new branch. (oops)
Now my local version is no longer the current master. Trying to push the changes gives me the following error: "The current branch could not be determined." If I check out the current master, I can commit as normal, but I lose all the changes I made after the mistake (but save in a backup local copy).
How do I push my new changes without checking out the current master? (branch, merge, etc.)
Or how do I connect my existing project to a new repository and start over?
(I tried changing the repository location to a new url, but I still have to check out the master to push..)
If the answer requires terminal commands, baby steps would be appreciated.
Here is the simple solution I use always - when I start developing on the master branch and forget to create new branch.
1. git stash
2. git checkout -b new-branch-name
3. git stash apply
4. git add *
5. git commit -m "commit"
6. git push origin new-branch-name .
That's all :)
Also as you are beginner you should play and learn git by playing this game and you will solve your problems related git by yourself :)
Related
Branch "abcd/child" is created from "abcd/master" . Changes are made to "abcd/child" and meanwhile "abcd/master" also have added changes. Now how to make sure the latest changes are pulled from "abcd/master" is available in "abcd/child" using git commands in git bash?
Assuming abcd is the name of your remote, here's how I'd do it:
git checkout child
git pull
git merge abcd/master
git push
When you checkout child, it'll probably say "set up to track remote abcd" or similar.
The git pull command does two things: It fetches all updates from the server (on all branches) to your local git repo, and it updates your branch to match what's on the remote.
The git merge abcd\master means to specifically bring in all of the commits that are on the remote's copy of the master branch. That's important because you may not have updated your local master to have all those commits.
Note also that you might get conflicts in the git merge if both abcd and master have edited the same sections of the same file. There's lots of help in resolving git merge conflicts.
Also: You want to make sure everything works after the merge. It's possible that the changes on master broke an API that you were using, so you may need to make edits to deal with that.
Update: My assumption about abcd being the name of the remote is wrong.
First, get the name of your remote with the git remote command. Mine goes like this.
git remote
origin
So I only have one remote, and I call it origin. That's pretty common. If you've got more than one remote, it'll be trickier.
So, with "origin" as the remote it goes like this:
git checkout abcd/child
git pull
git merge origin/abcd/master
git push
Obviously substitute the name of your remote if it's not origin.
Same caveats apply about conflicts and making sure it works.
1.Pull the latest code[
2.Commit the new code
3. When tried to push the code to bitbucket repository getting message "Local repository out of date[![enter image description here]
**
tried bothway Xcode push and cmd based push but no luck still getting this weird message
Note:
Xcode 12.4,
bit bucket
I don't understand, the image shows after the "pull"? If not, please edit your question and place the image in the correct place.
That message can be because someone else have pushed to your repo after the last time you pulled from it. You will need to revert all the X commits that you have done after your last succed push (save the work in another branch or whatever):
git reset --hard HEAD~X
Or reset your local branch to directly match your remote branch:
git reset --hard origin/remote-branch-name
Pull from the repo, make your commits and then you will be able to push again.
You have another option: PULL FORCE!!!
If you alredy known the "push --force" command, then pull force will sound you familiar, but in reality doesn't exist something like "pull --force", but exist a way to replicate that functionality in pull requests:
git fetch --all
git reset --hard origin/master
git pull origin master
(Replace "master" by your branch name)
With that command you overwrite your git history to match exactly the history of your remote repository branch. That will overwrite local changes (the ones that you have not pushed yet) and then you can make your commits and push them.
You can avoid this ackward situation by always working in a new branch only for your work, and when you need to integrate your changes you can make rebase or merge.
There are changes in your local repository that are not on the remote and vice versa, causing a conflict in your history.
You could try the following in your local repository (assuming your remote is called origin):
Make sure your local changes are committed (git commit -am "Some commit message")
Create a new branch (git branch new-branch-name)
Fetch the remote branch (git fetch origin)
Reset the target branch to the version on the remote (git reset --hard origin/target-branch-name)
Merge your newly created branch (git merge new-branch-name)
Push your changes to the remote (git push origin target-branch-name)
Finally resolved it by push the commits to the new PR and then merged the code with old PR
I am new to git-hub and when I create a pull request it shows a large amount of file changed, I am working on Laravel5 and being a trainee in a company I have to send the PR to my team head. So, How to save a fresh Laravel file in master branch and then after doing 1 or 2 changes I commit and generate PR?
Showing 87 changed files with 834 additions and 2,357 deletions
First, if you generate a PR, do so from a dedicated branch, not from master.
Second, whenever you are pushing to a fork (to make a PR), rebase your local branch first on top of the original repo branch.
cd /path/to/local/repo
git remote add upstream /url/original/repo
git fetch upstream
git checkout mybranch # in your case, for now master
git rebase upstream/master # rebase on top of the destination branch
# which will receive and integrate your PR
git push --force origin mybranch
Then make your PR: the diff will be only your work, as opposed to a delta representing evolution on upstream done while you were preparing your fix.
pushing to github was working fine. I think this problem started when i checked out a branch from github. How do i fix this? When i try to push to github now, i get the error "The current branch could not be determined."
Also, all my local commits do not show up with comments in either of my local branches. at least not in xcode 9 UI. I don't really know how to use the local git to check these things, so if someone wants to point me to documentation that would be helpful too.
I had this issue, you need to get down and dirty in Terminal :)
The issue is most likely a detached HEAD
This recovery is based on you have made changes whilst head detached and you want to keep these changes.
Navigate to your project directory and execute: git status
If you have a HEAD detached message then:
Commit changes: git commit -a -m "you commit comment here"
Create a local temp branch: git branch temp
Check out the previous branch (the branch you want to use i.e. master): git checkout master
now merge your recent changes (from the temp branch): git merge temp
Your all done, go back into Xcode and your back on your branch and everything as you left it :)
Hope this helps.
Type these commands (1-4) sequentially in your Command Prompt :
git commit -a -m "you commit message here"
git branch temporary
git checkout master
git merge temporary
Now head over to source control navigator pane in your Xcode project and delete the "temporary" branch from Branches Tab
Source Control navigator pane image
I had the same issue after checking out a previous commit and have found a fix.
In Xcode go to Source Control > Clone > Clone the repository you are trying to push and save it, then delete your old Xcode project and replace it with the cloned project and it should work as normal.
So to make a long story short, I've been working on a web app for the past few months. Recently I had to get a new laptop and cloned the repository from github onto my new machine... However whenever I commit changes to my app and attempt to use git push -u in the app's root directory i get the following message:
To git#github.com:acc/etc.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git#github.com:acc/etc.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
but when I try git pull git#github.com:acc/etc.git master I get a message telling me that the pull was aborted.
From github.com:acc/etc
* branch master -> FETCH_HEAD
error: Your local changes to the following files would be overwritten by merge:
config/routes.rb
test/fixtures/users.yml
Please, commit your changes or stash them before you can merge.
Aborting
so then i commit my changes using git commit -m 'fixing' and then attempt git pull again.
however this time I got messages stating that practically all my files had an "Auto-Merging CONFLICT"
am i totally screwed with this particular repository? I'm not really sure what to do since git is still somewhat new to me....
am i totally screwed with this particular repository?
No, but you will have to do a manual merge, since Git can't figure it out. git status will tell you which files need editing. The files themselves contain markers indicating where you should edit. When that's done, git push should work again.
If the changes aren't that big, consider making a copy of the entire folder/project in a different directory outside of the project, then git reset --hard HEAD will wipe out, erase and delete your recent changes.
You can then apply them again individually using your save3d copies for refernce.
Make sure sure you git add before git commit of course.
Finally if you get auto commit merge issues you can always just edit the files manually to resolve.