A growing list of common porcelain commands that make life easy.
Copy remote repositories.
Don’t download all the history, just the most recent commit.
Instead of downloading all the history of a repository just clone the repository at a specific tag or branch.
Adding and manipulating changes.
Get rid of any changes that havent been committed or staged for a commit.
Undo git add
.
bash git rebase -i HEAD~3
2. Write pick
next to the oldest commit 3. Write squash
in front of the commits to 4. Save the commit file and close the editor 5. Your text editor will reopen. Rewrite the commit message if you want. 6. Save the commit message and close the editor.
Merging branches.
This is useful when when you want to merge two branches that have diverged. That is, both branches have a common ancestor commit, but each branch has one or more unique commits. For example, say you have a branch called feature
on which development is complete and which is ready to be merged into main
. However, since feature
was branched, main
has new commits. The following will commands will merge the main
branch into feature
. This will make the feature
ready to submit to master
as a Pull Request.
Alternatively, you can use git merge
:
Russian nesting dolls, but for git
.
cd PARENT_PATH
git add SUBMODULE_PATH
git commit -m 'MESSAGE'
cd SUBMODULE
git checkout COMMIT_HASH
cd GIT_PARENT
git add SUBMODULE_DIR/
git commit
cd SUBMODULE_PATH
git checkout main
git pull
cd PROJECT_ROOT
git add SUBMODULE_PATH
git commit -m ...
git rm PATH
rm -rf .git/modules/PATH
where SUBMODULE
is the path
parameter in .gitmodules
:[submodule "NAME"]
path = PATH
url = ...
Notes on Computers
AWS · Bash · C · C++ · Cyber Security · Git · LaTeX · Linux · Networking · Python · Raspberry Pi · Tools · Vim
Notes on Math & Physics
Information Theory · Linear Algebra · Solid State Physics
Copyright 2021 · Eric D. Weise