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.
2 Answers
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
masterto other branch.
Namely I want to commit allmastercode to other branch in github and I don't want to delete past commits
In that case, you can:
- find the commit that newBranch was referencing before being reset: see "Recover from
git reset --hard?"
That is:
git checkout newBranch git reflog show git reset --hard <oldSHA1 of newBranch> checkout the files from
master(while staying in newBranch)git checkout newBranch git checkout master -- .
(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
masterinnewBranch, while keeping the history ofnewBranch.
If you had already pushed newBranch before, you will need to force the pushgit push --force
1 Comment
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.