Is there a good way to explain how to resolve \"! [rejected] master -> master (fetch first)\'
\" in Git?
When I use this command $ git push or
Please try this command to solve it -
git push origin master --force
Or
git push origin master -f
You can use the following command: First clone a fresh copy of your repo, using the --mirror flag:
$ git clone --mirror git://example.com/some-big-repo.git
Then follow the codes accordingly:
Adding an existing project to GitHub using the command line
Even if that doesn't work, you can simply code:
$ git push origin master --force
or
$ git push origin master -f
this work for me
git init
git add --all
3.git commit -m "name"
4.git push origin master --force
! [rejected] master -> master (fetch first) error: failed to push some refs to 'git@github.com:'
Successfully solved the problem using --force command.
so, you must used
git push origin master --force
pull is always the right approach but one exception could be when you are trying to convert a none-Git file system to a Github repository. There you would have to force the first commit in.
git init
git add README.md
git add .
git commit -m "first commit"
git remote add origin https://github.com/userName/repoName.git
git push --force origin master
Try this git command
git push origin master --force
or short of force -f
git push origin master -f