Most Important & Commonly Used GIT Commands: Part 2

In the 1st part of the most important and commonly used git commands we have talked about git setup, initialization, staging and snapshot, branching and branching. To read the full post click here

Today we will talk some more about these commonly used commands in git inspection and comparing, tracking path changes, ignoring patterns, sharing, updating and temporary commits. 

Inspect & Compare

Examining logs, diffs and object information

show the commit history for the currently active branch
git log

show the commits on branch A that are not on Branch B
git log branchB . . branchA

show the commits that changed file, even across renames
git log --follow [file]

show the diff of what is in branch A that is not in branch B
git diff branchB . . . branchA

show any object in GIT in human-readable format
git show [SHA]

Tracking Path Changes

Versioning file removes and path changes

delete the fie from project and stage the removal for commit
git rm [file]

change an existing file path and stage the move
git mv [existing path] [new path]

show all commit logs with indication of any paths that moved
git log --stat -M

Ignoring Patterns

Preventing unintentional staging or commiting of files

save a file with desired patterns as .gitignore with either direct string matches or wildcard globs
logs/
*.notes
pattern*/

system wide ignore pattern for all local repositories

git config --global core.excludefile [file]

Share & Update

Retrieving updates from another repository and updating local repos

add a GIT url as an alias
git remote add [alias] [url]

fetch down all the branches from that GIT remote
git fetch [alias]

merge a remote branch into your current branch to bring it up to date
git merge [alias]/[branch]

transmit local branch commits to the remote repository branch 
git push [alias] [branch]

fetch and merge any commits from the tracking remote branch
git pull

Rewrite History

Rewriting branches, updating commits and clearing history

apply any commits of current branch ahead of specified one
git rebase [branch]

clear staging area, rewrite working tree from specified commit

git reset --hard [commit]

Temporary Commits

Temporarily store modified, tracked files in order to change branches

save modified and staged changes
git stash

list stack-order of stashed file changes
git stash list

write working from top of stash stack
git stash pop

discard the changes from top to stash stack
git stash drop

That's it for the most important and commonly used git commands. To see the Most Important & Commonly Used GIT Commands: Part 1, click here.

Post a Comment

0 Comments