Reputation: 32721
After adding Git support, I'm not able to push to my repo. I pulled as the error suggested, but it didn't work either.
How can I resolve this?
svelte-flow on main [⇡] is 📦 v0.2.4 via v16.13.0
❯ ggp
To github.com:shinokada/svelte-flow.git
! [rejected] main -> main (fetch first)
error: failed to push some refs to 'github.com:shinokada/svelte-flow.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.
svelte-flow on main [⇡] is 📦 v0.2.4 via v16.13.0 took 2s
❯ gst
On branch main
Your branch is ahead of 'origin/main' by 2 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
svelte-flow on main [⇡] is 📦 v0.2.4 via v16.13.0
❯ ggp
To github.com:shinokada/svelte-flow.git
! [rejected] main -> main (fetch first)
error: failed to push some refs to 'github.com:shinokada/svelte-flow.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.
svelte-flow on main [⇡] is 📦 v0.2.4 via v16.13.0
❯ git pull
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (3/3), done.
Unpacking objects: 100% (4/4), 1.01 KiB | 172.00 KiB/s, done.
remote: Total 4 (delta 1), reused 0 (delta 0), pack-reused 0
From github.com:shinokada/svelte-flow
df125f9..381c351 main -> origin/main
hint: You have divergent branches and need to specify how to reconcile them.
hint: You can do so by running one of the following commands sometime before
hint: your next pull:
hint:
hint: git config pull.rebase false # merge
hint: git config pull.rebase true # rebase
hint: git config pull.ff only # fast-forward only
hint:
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
fatal: Need to specify how to reconcile divergent branches.
svelte-flow on main [⇕] is 📦 v0.2.4 via v16.13.0 took 2s
❯ git pull origin main
From github.com:shinokada/svelte-flow
* branch main -> FETCH_HEAD
hint: You have divergent branches and need to specify how to reconcile them.
hint: You can do so by running one of the following commands sometime before
hint: your next pull:
hint:
hint: git config pull.rebase false # merge
hint: git config pull.rebase true # rebase
hint: git config pull.ff only # fast-forward only
hint:
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
fatal: Need to specify how to reconcile divergent branches.
Upvotes: 0
Views: 426
Reputation: 16447
You have commits the remote branch does not have and the remote branch contains commits not in your local branch.
A-local
\
- remote
Git protects you from overwriting the changes in the remote branch using the error you received.
Git allows to merge those changes but you didn't tell it what stretegy to use. It suggests you the following options when pulling:
Merging branches means that you create a commit based of both commits (the local and remote one). This is the standard behaviour.
A - local - merge commit
\ /
- remote -
You can enable merging on pulls using git config pull.rebase false
.
Rebasing means you are taking your local branch and putting it on top of the remote branch:
A - remote - local
You can enable rebasing on pulls using git config pull.rebase true
or by pulling using git pull --rebase
.
You can also configure pulling in a way that it does not allow this case. If it would need to merge changes where both the local and remote branch have different commits, it would fail.
This can be configured using git config pull.ff only
Upvotes: 2