1/8/2024 0 Comments Github desktop force pushThis helps to make sure that you are at least not overwriting work from others: it will present an error message and refuse to push if the remote was modified since you last fetched. The push command has another option called -force-with-lease. Use -force-with-lease instead of -force. When connecting to a local git repository and trying to sync your local repository to the remote repository, the Push/Pull buttons can sometimes be greyed.This provides a much less obtrusive way to undo a mistake. ![]() However, consider using a tool that does NOT rewrite commit history, like git revert for example. The basic need for a tool to correct a mistake that you've already pushed, of course, remains. If, on the other hand, you were working on a feature branch that only you yourself are using, then of course feel free to step on the gas and use the -force option. Whenever you have pushed commits to a remote branch that is shared with your team, you should try NOT to use force push. Since it is so easy to destroy or at least impede your colleagues' work, here are a few "safety rules" around git push -force: ![]() Your "force push" changes this history and means theirs is not in line with the new one anymore. Also, even if no one else has pushed anything to the remote repository in the meantime, your colleagues might still have based their new work on the old commit history. ![]() This is a rather dangerous process, because it's very easy to overwrite (and thereby lose) commits from your colleagues. The -force option for git push allows you to override this rule: the commit history on the remote will be forcefully overwritten with your own local history. Only when you are up-to-date will you be able to push your own new commits to the remote. git push origin master -force Make sure your repo is up to date If the remote branch has changes that you don’t, they will be overwritten by this push. As described above, Git will normally only allow you to push your changes if you have previously updated your local branch with the latest commits from its remote counterpart. Once your local repo is in working order, you can force push to Github.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |