Source tree - fatal: A branch named 'main' already exists when check out - version-control

I accidentally commit my local changes to main branch.
Since there is branch protecting setting on main branch, the commit is failed to push to the remote.
But now I am 2 ahead on main.
When I try to checkout to the origin/main, error shows
How can I fix it on SourceTree?

Finally fix it by
Right click on the commit in the latest origin/main > Reset current branch to this commit > Done

Related

git reset --hard origin/master still giving different code

hello guys i want to ask about my GITHUB problem, why is my local master branch is different from remote?, i was modifying without committing then git branch -b and git add and git commit, and then after i push the new branch, create pull request, and merged to master, its different when i comeback to local master and git pull
i also already do git fetch origin and git reset --hard origin/master
the code is almost the same as remote but its just weird, a few declaration is missing and one entity naming is the same as my other branch
it turns out, that there is open tab in VSCode that i havent saved from another branch, close it out and dont save it solved the problem

Can't to push commits from local branch to github repository

I was committing and pushing in ordinary for my repository.
but once i used command of git checkout for change to the previous version of my repository.
after that i tried to commit and push, then it can not completed.
i try to use the --no-verify command to push the commit but it also not success.
error: failed to push some refs to 'https://github.com/ruwanliyanage123/Hair-4-U-Hospital.git'
i want to push my commit into github repository
Since you switched to a previous version of your repository, your head is most probably detached. You can't just go back anywhere in your history and make commits.
Consider making a branch from there and then commit to it.
Try to first check in which branch you are working do git branch, check is the one you are working. Then I sometimes do git pull to just make sure that the connection is working this should not delete your progress the you should be able to do git push. If you are afraid youll mess up first do a local back up of all project files except for the .git one which are hidden by default in windows.Lastly I would suggest never posting the actual link to your github repository in case whatever you are working is important, you can just replace with
https://github.com/user/projectname.git

Eclipse github How to change my Project message when i have pushed

I first commit blog, the messages is ok.
When I push next time, the message is no change.
I check my history, these were be pushed
What is master & HEAD?
How to change my Project message when I have pushed?
To modify a commit message right-click the commit and choose Modify > Reword. Technically, changing the commit message means to replace the commit and all its subsequent commits with a new commit due the message and the references to the parent(s) are part of the commit (you can see this by the fact that the Id of the commit has changed).
If you have already pushed the replaced commenit, the rewritten Git history requires a force-push: right-click the HEAD commit and choose Push Commit.... In the Push Branch master dialog check the option Force overwrite branch in remote if it exist and has diverged. But beware, rewriting the remote Git history is problematic when you collaborate with others via your GitHub repository. Therefor GitHub allows to disable force pushing.
What is master & HEAD?
The commit where you are (in your local repository) is marked with HEAD. The latest/head commit of a branch is marked with the branch name: master is the name of the main/default branch (like trunk in SVN/Subversion).

Restore branch deleted from GitHub

I had a branch on a GitHub project that I merged into master. I then clicked the 'delete branch' button on GitHub, and thought I was all set.
Turns out I wasn't, and I want to restore/reactivate the branch. I did not delete the branch on my local respository, nor did I run any git fetch/pull afterward. Just clicked the delete button on GitHub.
Wanted to sound out what a good next step should be. Thinking of doing git push from my local box but wasn't sure what the repercussions might be, would the remote repo on GitHub squawk about a dead branch being brought back, etc.
If you didn't remove your branch from your local machine, and you got rights to push to GitHub, you can restore it on Github by pushing it again
git checkout localBranchName
git push origin localBranchName
It doesn't matter if you make a fetch from Github, git wont remove your local branch until you explicitly tell it to do so with
git branch -D localBranchName
In fact, even if you had removed your local branch, if you merged it previously with master, you can restore it locally. You have to go to the last commit, prior to the merge and branch from there. Something like this for example:
git checkout master
git checkout -b localBranchName
git reset --hard HEAD~1 ( 1 is the number of commits you want to undo )
The second command will create a new branch pointing to your last commit on master
The third command will the last commit undoing (only on that branch ) the merge with master.
Another thing you can do is use "git reflog". That command is very usefull since it will show each time you moved between branches and/or commits.
Go to your list of commits. Find the commit with the merge and click on the pull request number (the number prefixed with #). This will direct you to a page with info about the merge and a button with the label 'Restore branch'. Click that and it is restored.
It looks like there is a "Restore branch" button now that shows up in place of the "Delete branch"

gitHub - Committing and Pushing Dev Branch Pushed to Another Branch

I have a dev branch. I made local changes, committed them git commit -m "blah" file and pushed these changes to my branch(ccap-biology-dev) git push origin ccap-biology-dev
. These changes were committed another branch(ccap-biology) as well as some temp files that my .gitignore file handles. None of these temp files are on my branch. I would like to avoid this from happening again. However, I do not know what I did incorrectly or the best way to correct this.
Steps I've taken to attempt to isolate the problem:
1. git remote -v:
origin https://github.com/Connexions/oer.exports.git (fetch)
origin https://github.com/Connexions/oer.exports.git (push)</code>
2. git branch -avvv
ccap-biology 0105488 [origin/ccap-biology] Update css/ccap-numbering.less
* ccap-biology-dev c674100 module2epub
remotes/origin/HEAD -> origin/master
remotes/origin/ccap-biology 0105488 Update css/ccap-numbering.less
remotes/origin/ccap-biology-dev c674100 module2epub
remotes/origin/master fa3d5fa Added some styling to solutions
3. branch log file doesn't reflect a commit on ccap-biology
4. gitHub Activity Feed does not show this push either
This happen during commit c674100 module2epub. What are the next steps to take to find out what happened? What is the best way to cleanup the branch that I accidentally pushed to?
Any help appreciated. Thanks ahead of time.