- Go to the original project and click fork
- Clone your fork
git clone git@github.com:username/repo.git
- Add an
upstream
remote for the original repositorygit remote add upstream https://github.com/origuser/repo.git
. - Checkout a new branch
git checkout -b BRANCH_NAME
- Make desired changes to the local repository on this branch.
- Pull new changes from remote
git checkout main
git pull upstream main
git checkout BRANCH_NAME
git merge main
- Push changes to your remote repository
git push origin BRANCH_NAME
. - Open a pull request on GitHub merging your changes with
upstream
(original) repository.
Once the pull request is accepted, you’ll want to pull those changes into your origin (forked repository).
- Change to main
git checkout main
- pull the changes
git pull upstream main
. - delete your branch using the GitHub website or local
git branch -d BRANCH_NAME
- delete the remote
git push origin --delete BRANCH_NAME
Prior to submitting your pull request, you might want to do a few things to clean up your branch and make it as simple as possible for the original repo's maintainer to test, accept, and merge your work.
If any commits have been made to the upstream main branch, you should rebase
your development branch so that merging it will be a simple fast-forward that won't require any conflict resolution work.
Fetch upstream main and merge with your repo's main branch
git fetch upstream
git checkout main
git merge upstream/main
If there were any new commits, rebase
your development branch
git checkout newfeature
git rebase main
git diff master:foo foo
git diff <local branch> <remote>/<remote branch>
git checkout FETCH_HEAD -- {file}
git fetch -p
git fetch -p upstream
git checkout master
git reset --hard upstream/master
git push origin master --force
https://stackoverflow.com/a/24768381
git remote set-url origin https://new.repo/url
git push origin master --force
or if origin is the same
git push origin master --force
alternatively to keep both existing (as upstream
) and new (as origin
)
git remote rename origin upstream
git remote add origin URL_TO_ORIGIN_GITHUB_REPO
git push origin master
Ref: https://stackoverflow.com/a/18957885
git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD
or
git diff-tree -r --name-only --no-commit-id HEAD@{1} HEAD
In case of git pull --ff-only
command, when many commits can be added, HEAD@{1}
(inside post-merge hook) gives the last commit before this command, while ORIG_HEAD
gives just HEAD^
commit.
git --work-tree=/var/www/html --git-dir=/usr/src/proj checkout -f
git fsck --full
git gc --prune=now
git lfs migrate import --no-rewrite pattern
or
git lfs track pattern
git add --renormalize .