failed to commit in master branch - github

I added a file into master branch (commit) and when I wanted to add another file: it says
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/XXXX/helloWorld.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
I really have this problem and I do not the logic behind it. Could sb please tell me why I see this problem and what I should do?
Thanks

You tried to push changes a branch that was not strictly in front of the origin branch.
Local: A -> B -> C
Remote: A -> B -> D
You will need to pull the remote changes (as instructed by the error message). If that merges ok, you can then push

Related

Cannot push on github suddently

Well, it is very weird. I'm using Github protection rules to enforce to make pull requests and to trigger TravisCI for every push. However, because of continuous translation, I need a user who should be able to push without making a pull request and avoiding TravisCI status check (for that I use [ci skip]). This user is included in the white list that Github provides in branch protection rules. It worked perfect since last week, suddenly when I try to push with this user I receive this:
remote: Resolving deltas: 100% (5/5), completed with 5 local objects.
remote: error: GH006: Protected branch update failed for refs/heads/master.
remote: error: Required status check "Travis CI - Pull Request" is expected. At least 1 approving review is required by reviewers with write access.
To https://github.com/*****
! [remote rejected] master -> master (protected branch hook declined)
error: failed to push some refs to 'https://*****'
It is very weird since it always worked till now. And, the user has permissions to push without making a pull request and it is skipping Travis with through the commit message so I do not understand why Github is asking me about status check and approvals.
The latest issue I had :
remote: error: GH006: Protected branch update failed for refs/heads/master.
remote: error: Cannot force-push to this protected branch
To https://github.com/org/project.git
! [remote rejected] master -> master (protected branch hook declined)
error: failed to push some refs to 'https://github.com/org/project.git
Because I'm admin/owner I was able to go and do the following and that helped me to resolve the push problem.
Steps :
--> Settings
-->Branches
--> Tick Allow force pushes
Permit force pushes for all users with push access.
That will do the work.
I solved it finally giving admin access to the user instead of just write access. Now it is able to push avoiding approvals and status check. But I don't understand why does not work just being in the white list of protection branch rules... It worked before, looks like GitHub made some changes...
Master [now Main] is a protected branch. You need to make a new branch and push that instead.
Seen in branch protection rules:
In my case a security rule was somehow created for the repo. This rule allowed only admins to push. I deleted that rule and things started working as expected.
Repo > Settings > Branches > Branch protection rules [Delete]
In my case a Branch Protection Rule was misfiring. Deleting the rule, then recreating it in GitHub fixed the issue.
In my case, I made a Pull (Rebase) first, and then I made Push
In my case git push origin HEAD fixed the problem.

git branch -vv seems to contradict itself when trying to work out whether by how many commits it is ahead/behind when tracking with remote branches

$ git status
On branch CurrAsOf18Jan2018
Your branch is up to date with 'remotes/bitbucketFrmWin/master'.
nothing to commit, working tree clean
But I know that my bitbucket repo is ahead by a couple of commits Ques:Do I have to always do a git fetch --all so that my local git can be sure - I thought I was tracking my remote repo bitbucketFrmWin - Anyways I do the following .....
$ git fetch --all
Fetching bitbucketFrmWin
From https://bitbucket.org/FreeFries/simplcontactsvcf
50d1fc6..d79d834 master -> bitbucketFrmWin/master
Good now my local repo can check against the fetched remotes whether it is ahead/behind
$ git status
On branch CurrAsOf18Jan2018
Your branch is behind 'remotes/bitbucketFrmWin/master' by 5 commits, and can be fast-forwarded.
nothing to commit, working tree clean
Okay I am happy with that it is what I thought
$ git branch -vv
* CurrAsOf18Jan2018 50d1fc6 [remotes/bitbucketFrmWin/master: behind 5] Pedantic but done - gitNotes.txt
bitbucketFrmWin/master 58470cd [CurrAsOf18Jan2018: behind 7] This is really crazy - Spent more than a week - Singleton still gives null pointer inJdbcExample2
Now this is what throws me [CurrAsOf18Jan2018: behind 7] (see last output line above) ... It should have said ahead by 5 - after all it is comparing the same remote repo branch. What am I missing in my understanding here ?
$ git merge --no-commit --ff-only d79d834
Updating 50d1fc6..d79d834
Fast-forward
.gitignore | 2 ++
gitNotesUpgradeInstall.txt | 38 ++++++++++++++++++++++++++++++++++++++
sqliteData/testtestdb.sqlite3 | Bin 278528 -> 0 bytes
3 files changed, 40 insertions(+)
create mode 100644 gitNotesUpgradeInstall.txt
delete mode 100644 sqliteData/testtestdb.sqlite3
I go ahead with the git fetch it fast-forward's my local branch - I tell it not to commit - but ignores my request and commits anyways - Why ?
Also my bitbucket branch master is actually already ahead at commit d79d834 but "git branch -vv" above does not show that commit sha signature in it's listing despite the fetch - Why ?
$ git status
On branch CurrAsOf18Jan2018
Your branch is up to date with 'remotes/bitbucketFrmWin/master'.
nothing to commit, working tree clean
Nevertheless git status knows now that it has caught up with my remote branch above and is happy
If someone can throw light on the questions posed above as to whether these are bugs or misunderstanding in the git work flow above - I would be grateful. Thanks.
I go ahead with the git fetch it fast-forward's my local branch - I tell it not to commit - but ignores my request and commits anyways - Why ?
Because there is no commit to be made: it does not make any commit: it just fast-forward your branch HEAD to the remote one.
And bitbucketFrmWin/master is a local branch, not remote one!
Its name is poorly chosen, as it matches the one of a remote: remotes/bitbucketFrmWin/master.
But being local, it is not surprising it too is behind its remote counterpart (which just got updated with git fetch bitbucketFrmWin).
If you want to see your remote as well as local ones, type:
git branch -avv
You will see a remotes/bitbucketFrmWin/master branch as well.

what will happen when merge, if both master and branch has changed in bitbucket

I have a branch from master in my local machine. I know how to merge something to master repo. but question is this.
Think some other developer has changed the master repository by pushing changes to it and at the same time I'm going to merge changes to the master repository from by branch.
What will happen at this situation.
What should I do in this type of situation. I tried to do following from my branch.
added my changes with -> git add *
then committed with -> git commit -m "my commit"
then push to my branch with -> git push -u origin my_branch_name
then changed the repository to master with -> git checkout master
then merged branch to master with -> git merge my_branch_name
up to this stage it was successful. then I tried to push with following command (before few minutes ago, another developer has pushed to master)
git push origin master
then it says followings.
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git#bitbucket.org:abcdef/cups.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
at this stage, what should I do.
should I get a pull after the merged step and then push (in this stage if i get a pull, what will happen.) or
do I have to do something like git stash, then push and something like that.
hope your help with this. thank your very much.
You need to Pull remote/master (to get all remote changes), then you are able to push your local changes.
Say, When you pulled remote/master there were 2 commits (A, B)
remote/master: A -> B
local/master: A -> B
Then other developer pushed a commit P to master
remote/master: A -> B -> P
local/master: A -> B
Then you've committed X in your branch (say, feature)
remote/master: A -> B -> P
local/master: A -> B
local/feature: A -> B -> X
Now Merged your feature with local/master
remote/master: A -> B -> P
local/master: A -> B -> X
local/feature: A -> B -> X
Now you've to pull your remote/master to fetch all commits of remote/master into local/master.
remote/master: A -> B -> P
local/master: A -> B -> P -> X # now local/master has P (sync with remote/master)
local/feature: A -> B -> X
Push your local/master to remote
remote/master: A -> B -> P -> X
local/master: A -> B -> P -> X
local/feature: A -> B -> X
You need to retrieve the work that has been pushed by the other person and integrate it locally before being able to push.
You can either perform a "git pull" directly, or better, perform a "git fetch", followed by either a "git merge" or a "git rebase".
The advantage of the fetch is to allow you to see what commit has been pushed by the other user. You can then decide to do a merge or a rebase. The rebase has the advantage of resulting in a "cleaner" tree.
If you have some ongoing work (files that you have staged), you need to decide if you want to integrate that in your next push. You then need to decide to discard them, stash them or integrate them to your next commit.

Pushing to GitHub - failed pushing to... (Repo) Premature EOF

Trying to push a project created before, to a private repository, it is the first commit to master branch remote, the repository is empty, just with a README file.
The push takes a long time and throws this error:
Failed pushing to... (Repo) Premature EOF
What is the reason?
Thanks
Edit local .git/config to add compression = 0 in [core] section.

How do you fork a repo whose upstream you've already forked?

I want to fork namecoin/namecoin, but I've already forked bitcoin/bitcoin. The latter is the upstream parent of the former. The forkchain is:
bitcoin/bitcoin -> vinced/namecoin -> namecoin/namecoin
When I fork namecoin/namecoin, Github just redirects me to my myuserid/bitcoin fork, instead of creating a new myuserid/namecoin fork. It appears to Github that they are the same project, but they are not.
Anyone know how to do this?
You can't do this "officially", but you can always add another remote for bitcoin and fetch from that.
git remote add bitcoin-orig git://the/bitcoin/repo/path
git fetch bitcoin-orig
# Merge into your 'master' (CAUTION: This might go badly)
git merge bitcoin-orig/master
# Create a local branch based on the origin
git co -b bitcoin-orig-master bitcoin-orig/master
# Take an individual commit from the original repo and put it into your 'master'
git log bitcoin-orig/master && git cherry-pick <SOME SHA>