GitHub feature branch - github

I have forked a repo with master branch . I have few changes here committed. I have to work a some feature now.how can I create a feature branch with latest from upstream and without the commits made to my master branch in my fork

Very simple actually.
Create the new branch feature, fetch upstream/master and reset feature:
# fetch latest `master` from `upstream` remote
$ git fetch upstream master
# create and checkout new `feature` branch off your current branch (`master`)
$ git checkout -b feature
# reset `feature` branch to `upstream/master`
$ git reset upstream/master --hard

Related

I messed up the Master Branch and project wont load, how do i make a new master branch?

So our Master branch is f*cked how can I delete that master branch and make a new master from my current working branch?
Thanks!
and I always keep getting this change being made. I literally do nothing and this happens. Is the .vs folder supposed to be on Github?
Also, I keep getting changes in the csproj file and cache. What are those? I'm new to GitHub.
Like any other branch:
# First, drop the messed-up branch:
$ git branch -D master
# Create a new master branch from your current branch:
$ git checkout -b master
# Force push it to GitHub:
$ git checkout master
$ git push --force origin master

How does a force push affect a cloned branch?

I was wondering if a branch is cloned from master. And now you remove some commits from master and force push. Will those commits be deleted on the cloned branch as well?
No: a branch starting from a commit of another branch will still reference that commit, even if that other branch changes (through a forced push) its HEAD.
You might want to rebase your branch on top of the new reset master, if you don't want to continue referencing those old commits.
git fetch
# see that origin/master has been reset
git checkout mybranch
git rebase --onto origin/master master myBranch
In that scenario, master is still locally at the old HEAD (from which you current branch is starting).
origin/master has been reset (and is up-to-date after the git fetch)
After that, you can reset your own local master:
git checkout master
git reset --hard origin/master
(make sure you don't have any work in progress when doing a git reset --hard)

Is it possible to delete specific commits from forked repo by github website

I searched this but unable to find my answer.
And I just want to know the non command line way to do this....
Or is there any other way to achieve this same ?
You can delete files (from a repo you own, like a fork)
But you cannot directly from the web interface delete commits.
For that you would need to clone, do an interactive rebase (dropping the commits you don't want) and git push --force.
Even a revert does not seem possible.
The OP adds:
Actually I have 3 branches one is master and rest two are patch-1 and patch-2 and I messed up with master branch before creating patch-1 and patch-2 branches so some useless commits are also cloned from master to patch-1 and patch-2 branch so please can you help me to delete those commits which are cloned from master?
No without cloning the repo though:
git clone /url/of/your/fork
cd yourfork
git remote add upstream /url/original/repo
git fetch upstream
git checkout -b patch-1 origin/patch-1
git checkout -b patch-2 origin/patch-2
Then replay your patches on top of upstream master:
git rebase --onto upstream/master master patch-1
git rebase --onto upstream/master master patch-2
Finally reset master to the upstream master branch:
git checkout master
git reset --hard upstream/master
And then push everything back to your fork:
git push --force --mirror

How to merge master branch in local feature branch

In one of case I have created an branch and started to work on. I keep on commit & push changes in local branch but did not merge in master & neither pulled any changes from master.
Now I'm done with local branch changes. I followed derekgourlay tutorial & followed following steps to merge my project.
git fetch origin
git rebase −p origin/develop
First it game me number of conflict which was obvious but changes that I committed in my local branch those are not there after merge.
Am I missing anything. Any suggestion?
You can merge develop branch with your feature branch.
$ git checkout feature
$ git pull origin develop # pull (fetch + merge) develop branch into feature
$ git push origin HEAD # update remote/feature

git rebase onto shows old commits that have already been merged

Essentially, I followed these steps: https://github.com/edx/edx-platform/wiki/How-to-Rebase-a-Pull-Request
The only difference is that I used get rebase onto master to sync master into my feature branch. This is my workflow:
git checkout master
git pull
git checkout <my branch>
git rebase onto master
git push -f origin <my branch>
However, when I now go into github to do a pull request, it is showing old commits that have already been merged.