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.
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 allmaster
code to other branch in github and I don't want to delete past commits
In that case, you can:
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 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