Basics | Git
Git States#
Working Directory =>
Staging Area =>
Repository (.git folder) =>
Remote Repositor
Commands#
help#
init#
initialize an empty git repo in current folder
status#
add#
move file from working directory to staging area
add all files in working directory to staging
all tracked files in the entire working tree are updated no file will be added
This adds, modifies, and removes index entries to match the working tree
commit#
use core editor which has been configured as git editor - multiline
inline
add all modified (tracked) files before commit
if you add close #issueNumber to end of message it will close the issue and associate the commit to that issue
log#
all commits
single line
asterisk based graph denoting our branching hierarchy
which commits are a part of which branches
history for all the branches
history of one file
show#
shows the last commit and a diff containing all changes
shows the details of annotated tag
ls-files#
show tracked files
reset#
unstage changes that have staged
reset to a commit id
basically, change where HEAD is pointing. it preserves staging area.
change HEAD pointing position and ustage commited changes
change HEAD position and wipe out pending changes
reflog#
shows all actions we've taken while in the repository
checkout#
revert unstaged changes
config#
at the user level not repo level
list of configs
add hist alias for showing history
diff#
difference between current working directory and HEAD
difference between a specific commit and HEAD
open configured diff tool
difference of two branches
branch#
show current branch
show all branches
delete branch
checkout#
switch to branch
create and switch to new branch
carry modifications into new branch
merge#
merge branch into current branch
resolve conflicts using mergetool
tag#
label some commit points
two types:
- lightweight: just label
- annotated: details
Tag the HEAD
Tag a commit
Tag the last commit of a branch
annotated
list tags
delete a tag
update a tag
stash#
stash working directory
list stashed files
apply and drop stash
remote#
by convention, the first and primary repo named origin
the list of remotes
update url
show remote details
push#
push current branch in Git v2.0#
push and set up a tracking branch relationship between the <branch> branch on the local repo and the <branch> on the remote repo#
push all branches#
push a tag#
push all tags#
push deleted tag#
push updated tag#
clone#
fetch / pull#
fetch and merge
rename and removing file#
edit#
rename will be staged automatically and git will know it's the same file
delete <file> and create an untracked <newfilename>
add all deleted and added files. So it detects the file has been renamed.
remove#
delete <file> and stage changes
.gitignore#
one pattern or expression per line
Branches#
name for timeline
Merge#
Fast-Forward#
- when no additional work has been detected on the parent branch
- git will simply apply all commits from the other branch to parent branch, as if we never branched off to begin with
- we can disable it
Automatic#
- when non-conflict merge detected
- preserve both timelines
- will have a merge commit
Manual#
- conflict
- resolve and commit a merged commit
Rebase#
rewinds the current commits that are on your branch to a point to where the branch you're merging in originally diverged then playing back the commits that happend on the branch that you're wanting to bring in then playing on top of that, any commits that have happened on the branch that you're currently on
it will rebase instead of merge
Markers (Pointers)#
Head#
- Point to last commit of current branch
- Can be moved manually or by switching branch
issue and PR#
for associating a commit to issue we can add a comment and in comment we can use # to find the issue/PR