last modified: 25-feb-2017 (09:41)
This is part II of two part series about force pushing in git.
In previous article, we have discussed theory about
force push. In this article, I will try to demonstrate all the
scenarios by creating local repositories.
Create a local
bare repo - it will serve as our remote repository
Create another repository with name local1. This will be our local repository.
Now we have total 2 repositories.
myremote as origin of
Add a file with some content in
local1 repo, commit and push it to remote.
Now we have two commits from
myremote and create another repo with name
At this point, we have both
local2 pointing to same code and are synced with remote.
Reset the last commit in
local2, modify the file and push it to remote.
At this point, remote must have our last commit (third line) and previous commits.
local1 and force push you commit. Remote history will be overriden and out last commit from
local2 will disappear.
Confirm it by cloning another repo
local3 will be same as
local1, see! commit from
local2 has disappeared
In similar manner, you can create other scenarios.
Git isn’t hard or complex, you jsut have to spend more time to get familiar with it.