1

I am new on smartgit-ubuntu and I have a problem. I started to use smartgit for gui. I have a project on github and I have 2 branches which are master and new branch. I cloned project on smartgit and I changed code in new branch. Also, I pushed code to new branch and code is on github-new branch. I did mistake and I want to overwrite new branch with master code. In sum, I want to change new branch code with master code and I want to push it to github-new branch. How can I do? Thanks advance.

wowo
  • 173
  • 3
  • 11

2 Answers2

1

You can reset your local new branch to master, then force push it.
An example of reset with SmartGit is seen here.

Even without smartGit, you can do that in command-line:

cd /path/to/my/repo
git checkout master
git pull
git checkout newBranch
git reset --hard master
git push --force -u origin newBranch

However, as the OP comments:

This reset deletes github commits and copy master to other branch.
Namely I want to commit all master code to other branch in github and I don't want to delete past commits

In that case, you can:

That is:

git checkout newBranch
git reflog show
git reset --hard <oldSHA1 of newBranch>

(note the final -- .: "dash-dash-space-dot" at the end of the second checkout)

  • add, commit and push: you will add, commit and push files from master in newBranch, while keeping the history of newBranch.
    If you had already pushed newBranch before, you will need to force the push

    git push --force
    
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • is there any way to overwrite local branch and push it to github. This reset deletes github commits and copy master to other branch. Namely I want to commit all master code to other branch in github and I don't want to delete past commits. – wowo Apr 02 '18 at 08:01
1

In any git to get a branch to point to a specific commit (including another branch) you need to reset. Specifically in smartgit How to checkout and reset using smartgit? indicates you should have reset in your gui - just checkout the new branch, and reset it to master.

kabanus
  • 24,623
  • 6
  • 41
  • 74