13  Miscellaneous

This section contains miscellaneous troubleshooting information that does not have a natural home elsewhere, at the moment.

13.1 Partial Push

Sometimes you make a lot of commits locally that you haven’t pushed to the remote. If this happens, occasionally, you may want to push only a subset of the commits to the remote. This could be because you’re not sure that all of the commits are complete enough to be shared, and you may want to edit them later on. It could also be that you tried a regular push, but it failed, and pushing only a subset of the commits is a way to troubleshoot the problem.

git push origin commit-id:branch-name

13.2 Forking/Duplicating Your Own Repository

It’s not possible to fork your own repository on GitHub. However, you can create a copy of it. The steps are as follows:

  • Create a new repository on GitHub.
  • Clone your original repository to your local machine.
  • Add the new repository as a remote (origin).
  • Add the old repository as the upstream (i.e. the origin of the material)
    • This allows you to track changes to the original repository, and pull them into your new repository.
  • Push the local copy of the new repository to the new remote.
  • Check for other branches in the original repository
    • Checkout each branch in turn
    • Push each branch to the new remote
    • Repeat for all branches
git clone [email protected]:arnold-c/psu-intro-to-git.git psu-intro-to-git-copy
cd psu-intro-to-git-copy
git remote set-url origin [email protected]:arnold-c/psu-intro-to-git-copy.git
git remote add upstream [email protected]:arnold-c/psu-intro-to-git.git
git push -u origin main
git branch -a # list all branches in the original (remote) repository
# git checkout other-branch-name
# git push -u origin other-branch-name