Forked private repository, duplicate and make public repository - github

I have forked a private repository, can I duplicate and make a new public repository on my github ...?

Mary, private forks can’t be made public. You can copy to a new repository easily though.
git clone --bare https://github.com/otherusername/private-repo.git
cd private-repo.git
git push --mirror https://github.com/yourname/public-repo.git
cd ..
rm -rf private-repo.git
git clone https://github.com/yourname/public-repo.git

Related

GitHub: How can I transfer a repo that I own to an organization I own and keep it on my private account?

I have read the help page and I have managed to transfer it to my organization but it is then myorg/repo rather than myuser/repo. I can create a new repo as my org which is myuser/repo though so there must be some way to transfer it like that, but I can't find it.
You have a two options:
Fork the repo (won't be private though)
Clone the repo:
git clone <repo url>
cd <repo directory>
git add . && git commit -m "<commit message>"
git push origin <branch>
Cloning it is the only way to have the same repo but private.

GitHub: how to fork public repo to enterprise, edit enterprise version but still update with public fork

This is a follow up to the question Is it possible to fork a public GitHub repo into an enterprise repository?
I want to fork the public project github.com/foo.git and work on it on my enterprise server, under the name github.enterprise.com/bar.git. However, I want to keep them linked so I can pull any changes on the master. In other words, I am going to create some new codes and edits in my enterprise bar.git, but whenever the authors of foo.git update their master repo, I want to pull those changes. So I followed the following steps.
Create an empty repository on github.enterprise.com/bar.git
Fork github.com/foo.git on my public GitHub account github.com/MyPublic/foo.git
Rename my public repo as to bar.git so it's github.com/MyPublic/bar.git
Create a bare clone of my new fork on my computer
git clone --bare https://github.com/MyPlublic/bar.git
Change directories into the bare clones folder:
cd bar.git/
Push the repository with the --mirror flag to my enterprise GitHub
git push --mirror https://github.enterprise.com/bar.git
git remote set-url --push origin https://github.enterprise.com/bar.git
Now I have the bar.git/ directory on my computer, which is BARE:master and not an editable version of the repo. I have bar.git repos on my personal public GitHub.com account and on my Enterprise server. The next things I need to do are (1) clone the enterprise repo onto my computer and edit it; (2) commit and push those changes to the enterprise repo; and (3) I also want to pull changes from the master foo.git repo when they happen.
I'm assuming I just do a standard clone, commit, and push for (1) and (2), i.e.
git clone GitHub.enterprise.com/bar.git
git commit
git push
Is it actually possible to do #3? I'm thinking that in my computer's bar.git/ directory, I execute
git fetch -p origin
git push --mirror
and then in the bar/ directory, I execute a standard git pull?

Forking private Github Repo that may get deleted

I am taking over a project from a previous contractor and all the code is in a private Github repo. I forked it which now appears as a private repo in my account but I read that if he closes his private repo (which will happen) then my forked repo will get deleted.
So, what's the best way to get this into my own Private repo with all the history behind it? Should I just clone the fork now to my own Private repo?
Just clone your fork using --bare option, and next push it to another remote using --mirror option:
$ git clone --bare https://github.com/exampleuser/old-repository.git
$ cd old-repository.git
$ git push --mirror https://github.com/exampleuser/new-repository.git
For more details look into this GitHub help page.

How to migrate a private Bitbucket repository to a public Github repository

How can I migrate a private Bitbucket repository to a public Github repository?
Make a "bare" clone of the repository (i.e. a full copy of the data, but without a working directory for editing files) using the external clone URL. This ensures a clean, fresh export of all the old data.
Push the local cloned repository to GitHub using the "mirror" option, which ensures that all references (i.e. branches, tags, etc.) are copied to the imported repository.
Here are all the commands:
git clone --bare https://bitbucket.com/user/repo.git
cd repo.git
git push --mirror https://github.com/ghuser/repo.git

Having a private branch of a public repo on GitHub?

I have a public PHP project in a GitHub repo, which contains just one branch (master).
I want to have a separate branch/fork that is private for me (I have paid for private GitHub repos). I would like to be able to merge changes from the private branch/fork to the public repo, and vice versa.
With that in mind, here are my questions:
Can I have a private branch on a public repo?
Can I fork my own public repo into my own private branch/fork?
If both of the above are possible, which is the best way forward? If neither, how should I proceed?
Duplicate your repo.
Make the duplicated repo a private one on GitHub.
Clone the private repo to your machine
Add a remote to your public repo (git remote add public git#github.com:...)
Push branches with commits intended for your public repo to that new public remote. (make sure you don't accidentally commit private-only code)
You can bring in changes to your public repo using 'git fetch public' and then merge them locally and push to your private repo (origin remote).
Is it possible to have a private branch on a public repo?
On GitHub, your repository is either public or private; you cannot selectively "privatize" just a branch.
Can I fork my own public repo into my own private branch/fork?
You can clone your public repo to your local machine, branch as needed, and simply not push your "private" branches upstream (by specifying which branch to push to origin: git push origin master or git push origin branch-i-want-to-be-public:master).
Which is the best way forward/how should I proceed?
In order to take advantage of GitHub for both your public and private development, I would suggest forking your public branch within GitHub, changing the settings of the new fork to "Private", and then cloning the private version down to your local machine. When you're ready to make changes public, push everything up to your private fork on GitHub and then use pull requests to selectively copy branches to the public repo.
To make a repository private on GitHub, you must have an upgraded (paid) account. If you're only rocking the free account, you can still use the first process I suggested — clone public to local machine, branch, and push specific "public" branches to origin — without needing a private repo.
If you have a paid GitHub account, or are using another service that offers public and private forks and pull requests (such as BitBucket), then you can use either of the above approaches to make your code public.
There is another solution which I find better as it doesn't result in duplicate repos on the same machine.
Make a branch with the stuff you want private.
Make a new repo on GitHub, set it to private.
Add new GitHub repo as a second remote to your repo on your machine.
Push private branch to second remote.
End result is 1 repository with 2 remotes. 1 public, 1 private.
Just need to be careful about which you push to so name accordingly.
1.) Is it possible to have a private branch on a public repo
From what I know, no.
2.) Can I fork my own public repo into my own private branch
No, you can't fork a full repo (1-n branches) into a single branch. Well actually you could, if you just fork the one branch of the full repo. Just add it as a remote or start from a clone.
You might also be interested in Sparse checkouts.
3.) If both the above the are possible which is the best way forward
n/a
4.) If neither are possible how should I proceed?
n/a
To create private branch (downstream) of a public repository (upstream):
Initialize repository
$ git init private-repo
$ cd private-repo
Add remotes
$ git remote add upstream git#github.com:<username>/public-repo.git
$ git remote add origin git#github.com:<username>/private-repo.git
$ git remote --verbose
Initial commit
$ git commit --allow-empty --message "Initial commit"
$ git push --set-upstream origin master
Create development branch
$ git checkout -b develop
$ git push --set-upstream origin develop
$ git branch --all
Merge upstream into development branch
$ git fetch upstream master
$ git merge --allow-unrelated-histories upstream/master
$ git push
Some changes on repository...
# Do some changes...
$ git add .
$ git commit -m "Some changes"
$ git push
Apply upstream changes...
$ git fetch upstream master
$ git log --all --graph --oneline
$ git merge upstream/master
$ git push
Merge development branch to master
$ git switch master
$ git merge develop
$ git push
$ git log --all --graph --oneline
For next clones:
Clone repository
$ git clone git#github.com:<username>/private-repo.git
$ cd private-repo
Add upstream remote
$ git remote add upstream git#github.com:<username>/public-repo.git
$ git remote --verbose
Switch to development branch and get upstream changes
$ git switch develop
$ git fetch upstream master
$ git log --all --graph --oneline
$ git merge upstream/master
https://gist.github.com/amir-saniyan/a3c76b7e545e3d84f82f27e6c6579245