- Adding a submodule
- Amend previous commit message
- Change remote origin
- Creating a fork and tracking
- Delete branch locally
- Git reset a squashed commit
- Merging Master instead of Rebase
- Remove locally commited commits
- Track and Fetch another users branch
- Working on branch that depends on another dev branch
- View changes in a git commit by hash
- precommit hooks
- Pull a remote branch from repo
A submodule is a github project within a github project. This has the benefit of using another github project code in a main project.
git submodule add <uri> local-path
Adding to the previous commit without a new commit message
$ git add <some-file>
$ git commit --amend
When you would like to change the previous commit message in history.
$ git commit --amend
$ git remote set-url origin [email protected]:<some-user>/<some-project>.git
git clone [email protected]:YOUR-USERNAME/YOUR-FORKED-REPO.git
cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
git pull upstream master
First command deletes a branch that is not merged. Second command force deletest the branch CAREFUL.
$ git branch -d <name-of-branch>
$ git branch -D <name-of-branch>
If you want to undo a squashed commit.
Shows the git command history.
git reflog
Resets the history to the position number displayed in git reflog
this should be before the squash
git reset --hard HEAD@{5}
This a good technique to use in teams that need to work on the same branch.
$ git checkout master
$ git pull master
$ git checkout feature
$ git merge master
Previously I was using git rebase master
and force
pushing updates.
The problem with this approach is that it breaks the history for other developers
working on the same branch.
Add the user and their repo.
git remote add <name-of-user> <address-of-user-github-repo>
Fetch the users branches.
git fetch <name-of-user>
Checkout the users branch
git checkout --track <name-of-user>/<branch>
When first pulling a project, you need to install all the submodules.
git submodule init
git submodule update
When you need to remove commits that are added and committed locally but not pushed to the repository.
NOTE: the needs to be the one hash BEFORE the commit you want to revert.
$ git reset <previous-commit-hash>
This is a scenario where a developer is working on feature_a
that is branched off master
.
The developer is waiting for that branch to be merged but needs to start working on feature_b
.
But feature_b
depends on the work of feature_a
.
So this is a way for the developer to start working on feature_b
while feature_a
is being reviewed and eventually
be able to merge to master without any complications.
- Checkout
feature_a
$ git checkout feature_a
- Create the
feature_b
branch offfeature_a
and check it out.
$ git branch feature_b
$ git checkout feature_b
- Whenever
feature_a
changes while working onfeature_b
, pull the changes tofeature_b
$ git checkout feature_b
$ git rebase feature_a
- Once
feature_a
is merged, do a final special rebase to 'graft'feature_b
on to master, this means thatfeature_b
is a branch that is fully branched off master and no longer dangling offeature_a
.
$ git checkout master
$ git pull master
$ git checkout feature_b
$ git rebase --onto master feature_a feature_b
git show --color --pretty=format:%b aa737f6ab8a2b03810d04508a0a88980ca952c56
pip install pre-commit
create a file named .pre-commit-config.yaml
- SAMPLE
.pre-commit-config.yaml
- runs the black formatter before commiting
repos:
- repo: https://github.com/psf/black
rev: stable
hooks:
- id: black
language_version: python3.6
- Install the precommit hooks
$ pre-commit install
When needing to pull a remote branch from the repo locally.
git pull origin <name-of-remote-branch>