Basic GIT Commands Flashcards
working directory
where you have a local copy of the git repository checked out
staging area
where files are added before being committed
git init
initializes a directory as a Git repository
git clone [url]
copy a git repository so you can add to it
git add [file]
adds a new file or new modifications of an existing file to the staging area
git status -s
view the (short) status of your files in the working directory and staging area
git diff
shows diff of unstaged changes
git diff
cached
git diff HEAD
show diff of all changes (staged or unstaged)
git diff
stat
git commit -m ‘message’
records a snapshot of the staging area (all those files and modifications that have been added to it)
git commit -a
automatically stage all tracked, modified files before the commit
git reset HEAD
[file]
git branch
list your available branches
git branch [branchname]
create a new branch
git checkout [branchname]
switch to a new branch context
git checkout -b [branchname]
create and immediately switch to a branch
git branch -d [branchname]
delete a branch
git merge [branchname]
merge a branch context into your current one
git log
show commit history of a branch
git tag -a [tag] [commit SHA]
tag a point (the current commit or the given commit) in history
git remote
list your remote aliases
git remote add [alias] [url]
add a new remote repository of your project
git remote rm [alias]
removing an existing remote alias
git fetch [alias]
synchronize your local repository with another repository
git pull
git fetch; git merge
git push [alias] [branch]
push your new branches and data to a remote repository
git merge [alias]/[branch]
merge into your current branch anything new you see on the server
git branch -v
Be a little more verbose and show remote url after name
–dry-run
show what would be committed
git commit –amend
amend previous commit
git config –global
user.email “Eric.Zhuang@monitisegroup.com”
git checkout .
This checks out the current index for the current directory, throwing away all changes in files from the current directory downwards.
–soft
Does not touch the index file nor the working tree at all, but requires them to be in a good order. This leaves all your changed files “Changes to be committed”, as git-status would put it.
–hard
Matches the working tree and index to that of the tree being switched to. Any changes to tracked files in the working tree since are lost.
–mixed
Resets the index but not the working tree (i.e., the changed files are preserved ut not marked for commit) and reports what has not been updated. This is the default ction.
git reset HEAD@{1}
undo git reset HEAD~
–amend
$ git reset –soft HEAD^
$ … do something else to come up with the right tree …
$ git commit -c ORIG_HEAD
git reset –soft HEAD^
This is most often done when you remembered what you just committed is incomplete, or you misspelled
your commit message, or both. Leaves working tree as it was before “reset”.
git reset –hard HEAD~3
Rewind the master branch to get rid of those three commits
The Git Index
The index is a binary file (generally kept in .git/index) containing a sorted list of path names, each with permissions and the SHA1 of a blob object
git ls-files
git ls-files can show you the contents of the index