Github: fork into new branch - github

I need to fork the branch from PrestaShop:develop into a different branch and not username:develop
How can this be done?

Fork = clone repository of another user on Github, and make GitHub know about it
1) Fork the repo as usual with the fork button
2) If you want to rename the branch
git branch -m old_branch_name new_branch_name
git push origin :old_branch_name
git push origin new_branch_name
If you want to rename not branch but the whole repository - see, How.
If you want to have both branches in one repository, it is not a GitHub feature named fork, it is branching: branch ..., or checkout -b:
git checkout -b new_branch old_branch
git push -u origin new_branch
In that case you should not cope with GitHub forks to create a new branch from yours existing one.

Related

Moving the content of one branch in a repo to another branch under the another repo

I have one branch name branch1 under the main Repository Repo1.
I want to move the content of branch1 to another branch which exists under another repo say repo2. So it's like:
Repo1-> branch 1 (latest code).
Repo2-> branch 2 ( empty branch).
I want to move content or copy the content from branch 1 -> branch 2.
Can you please help me go through a few solutions?
You can indeed push any branch to another repository.
Howver, then end reuslt will be an orphan branch in the second repository
cd /path/to/repo1
git switch branch1
git remote add repo2 /url/repo2
git push repo2 branch1
The new branch would not be related with any other repo2 branch though:
cd /path/to
git clone /url/repo2
git merge-base main origin/branch1
<nothing>

How do I switch my fork to a different Github branch?

I made fork a branch of a Github repository. I made changes to my fork.
A new branch was added to the repository. I want to merge the changes from the new branch to my fork, preserving my changes to my fork.
I don't own the original repository.
How do I do this?
#add the remote to your fork.
git remote add upstream https:/github.com/whoever/whatever.git
#update your personal fork while keeping changes (swap master with the branch you want).
git pull upstream master --rebase --autostash
This should add the remote repository to your git repo (your fork) and then you tell it to fetch the changes from that branch and add your own changes on top.

Is there any way to clone a specific brach in git desktop?

I tried but its cloning whole repository. I wanted to clone only specific branch in that repository
Thanks in advance
You only can clone a whole repository except a branch, the code is:
git clone -b mybranch --single-branch git://sub.domain.com/repo.git
If you already have the repository cloned, you can refresh the branch you want, if you have forked the project you can refresh the specific branch you want. the code is:
git checkout 'branch if you want to change to refresh it'
git pull <URL of REPOSITORY> 'branch that you want to refresh it'
git commit -m "message"
git push upstream 'branch that you want to refresh it'

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

Unable to find branch in git repo

In the current directory. I had made a repository yesterday from this directory.
now:
git branch foo
After doing some changes in the file..
git add .
git commit -m "commit1"
git push.
I am unable to see the branch from my repo on github. While git branch does show this foo.
What you did is creating a local branch;
you will need alternatively to make it a remote branch:
git push <remote-name> <branch-name>
where <remote-name> is usually origin