Professional Documents
Culture Documents
Sertalpbilal Git-Commands
Sertalpbilal Git-Commands
Sertalpbilal Git-Commands
git init Create git repository here (decentralized) git diff branch1..bra‐ See differences between branch1 and
git init --bare Create bare git repository (centralized) nch2 branch2
git clone repo Clone repository at address repo You can use commits instead of branch names. HEAD refers to
current point in git.
git clone -b branch repo Clone branch from repository
Reseting
Status
git reset --soft Stage all changes since commit (used for
git status List changes
commit squashing)
git status --short --branch List changes (compact)
git reset --hard Discard all local changes and reset to last
git log Display commit history
commit
git log --oneline --decorate --graph - Display visual commit history
-all Maintenance
git config --global core.autocrlf true Ignore OS-specific line
git revert commit Creates a new commit out of an old commit
endings
(turn back in history)
git clean -dfx Delete all untracked files and directories
Commits
Dangerous
git add hello.py Add hello.py (or stage changes)
git clean -dfxn Dry run - Show which files will be deleted
for next commit
git gc --aggressive -- Reduce file size of repository by pruning
git rm --cached hello.py Remove hello.py from git tracking
prune=now
git checkout -- hello.py Discard all local changes to
git checkout file Discard local changes to file
hello.py
bfg -delete-files file BFG cleans sensitive data file
git add -u Stage all changes under tracking
git add -A Stage all changes (new files and Remote Management
deletions included)
git remote add target Add remote target at address repo
git update-index --assume-‐ Ignore changes to hello.py locally
repo
unchanged hello.py
git remote -v List all remotes
git add --interactive Review and stage changes
git remote set-url Changes the address of remote target
git commit Create a commit (snapshot)
target repo
git commit -m "message" Create a commit with message
git push -f origin Forces origin/master branch to be moved to
git commit -a Commit every change under commit:master commit
tracking
git pull (--rebase) Push existing commit to target/branch
git commit -ammend Combine current and last commit target branch
(correction)
git push target Push branch to target/branch
git diff Show all unstaged differences branch
git diff --cached Show all differences including git push target Push local branch1 to target/branch2
staged ones branch1:branch2
git push -u target Push and track target/branch. It sets
branch upstream for default pull / push
git push target -- Deletes target/branch at remote
delete branch
git fetch target Update branch information of target remote git submodule update --init -- Pull all submodules (linked reposi‐
recursive . tories)
Note: repo might start with git@ or https. When it starts with git@
an SSH key is needed for pull/push operations. git submodule status folder Show the status of submodule
under folder
Branch management
Use
git for-each-ref --sort=committerdate refs/heads/
--format='%(HEAD) %(refname:short) - %(objectn‐
ame:short) - %(contents:subject) - %(authorname) (%
(committerdate:relative))'
to print summary of each branch, last commit, and other info
Tag management
Semantic Versioning