Initial Cloning https://stackoverflow.com/questions/67699/how-to-clone-all-remote-branches-in-git
git clone https://github.com/darcys22/loki-core.git loki_source
list all remote branches
git branch -a
checkout dev
git checkout origin/dev
create new branch for dev after checking out remote branch
git checkout dev
View current sources
git remote -v
Add new source:
$ git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
git remote add upstream https://github.com/loki-project/loki-core.git
create the new branch whilst on dev
git checkout -b pull-request-name
git push -d <remote_name> <branch_name>
git branch -d <branch_name>
git checkout dev
$ git pull https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git BRANCH_NAME
git pull upstream/dev dev
git pull upstream dev
From within the branch you are working on
git checkout pull-request-name
git pull origin dev
git diff --no-index --word-diff old_file.txt new_file.txt
Use triple dot syntax between branches
git diff dev...hotfix-branch
When I’m happy with the functionality in my local branch. When the bug seems to be fixed or the feature seems to be doing what it’s supposed to do and the test suite runs fine locally.
I then clean up the commit series with git rebase -i
(or if it is a single commit I can instead use just git commit --amend
).
git cherry -v dev hotfix-branch
Fetch the reference to the pull request based on its ID number, creating a new branch in the process. Branchname can be be anything you want (Not dependant on PR details)
$ git fetch origin pull/ID/head:BRANCHNAME
Switch to the new branch that's based on this pull request:
[main] $ git checkout BRANCHNAME
> Switched to a new branch 'BRANCHNAME'
git remote add coworker git://coworkersUsername/repo.git
git fetch coworker
git branch --all # choose a branch
git checkout --track -b aBranch coworker/aBranch
- Make sure your branch is up to date with the master branch.
git fetch upstream
git rebase dev
- Run git rebase
-i master
. - You should see a list of commits, each commit starting with the word "pick".
- Make sure the first commit says "pick" and change the rest from "pick" to "squash". -- This will squash each commit into the previous commit, which will continue until every commit is squashed into the first commit.
- Save and close the editor.
- It will give you the opportunity to change the commit message.
- Save and close the editor again.
- Then you have to force push the final, squashed commit:
git push --force-with-lease origin
.
# create a new branch
git checkout -b new_clean_branch
# apply all changes
git merge original_messy_branch
# forget the commits but have the changes staged for commit
git reset --soft main
git commit -m "Squashed changes from original_messy_branch"
git push <remote> <source branch>:<dest branch>
git push origin cleaned-up-branch:original-branch-on-PR
git submodule add -b stable https://github.com/pybind/pybind11 external/pybind11