git¶
Git is a fast, scalable, distributed revision control system (https://git-scm.com)
Set your identity
git config --global user.name "John Doe"
git config --global user.email [email protected]
Enable color support for commands like git diff. Disable with never or
partially disable -- unless otherwise applied -- with false.
Stash changes locally. This will keep the changes in a separate changelist, -
called 'stash', and the working directory is cleaned. You can apply changes from the stash at any time.
Apply stash from the stash list, but does not remove the stash from the list
Commit in the past. Newer versions of Git allow --date="2 days ago" usage
Change the date of an existing commit
Push to a specified repository
git push [email protected]:<username>/<repository>.git
Sync a fork with the master repo
git remote add upstream [email protected]:name/repo.git # <-- Set a new repo.
git remote -v # <-- Confirm new remote repo.
git fetch upstream # <-- Get branches.
git branch -va # <-- List local - remote branches.
git checkout master # <-- Checkout local master branch.
git checkout -b new_branch # <-- Create and checkout a new branch.
git merge upstream/master # <-- Merge remote into local repo.
git show 83fb499 # <-- Show what a commit did.
git show 83fb499:path/to/file.ext # <-- Show the file as it was in 83fb499.
git diff branch_1 branch_2 # <-- Check difference between branches.
git log # <-- Show all of the commits.
git status # <-- Show the changes from the last commit.
Display the commit history of a set of files
Import commits from another repo
View changes which are new on a feature branch
Show changes to files WITHOUT considering them a part of git. This can be
used to diff files which are not part of a git repo!
Perform a shallow clone, to only get the latest commits, which helps to save
data (good for limited data connections) when cloning large repos.
Remove all stale branches; ones that have been deleted on remote. So if you
have a lot of useless branches, delete them on GitHub and then run this.
Revisions can also be identified with :/text. So, this will show the first
commit that has the string "cool" in its message body.
Apply only the changes made within a given commit. This is different to the
merge command, as it would otherwise apply all commits from a branch.
Undo last commit. If you want to nuke commit C to never see it again
(F) A-B-C ↑ master
Undo last commit. If you want to undo the commit, but keep your changes
(F) A-B-C ↑ master
Porcelain-ly List files changed in a given commit; user-facing approach
See everything you have done, across branches, in a glance, then go to the
place right before you broke everything.
Move your most recent commit from one branch, to stage it on [BRANCH]
git reset HEAD~ --soft
git stash
git checkout <branch>
git stash pop
git add .
(
git config --global user.email "[email protected]"
git config --global user.name "nιcнolaѕ wιlde"
git config --global init.defaultBranch main
git config --global user.signingkey 78E2E084522FB8A14C0D9AED800C8DB8B299A622
git config --global commit.gpgsign true
git config --global pull.rebase false
)