You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
git clone <url (either ssh or https)> --> clone repository from remote server
git init --> initialize a new repository in current working directory
git pull origin <branchName> --> pull branch from remote repository
git add <fileName> --> add file from working directory to staging area
git commit --> commit to local repository (will open default editor to provide commit message)
git commit -m "<commit message>" --> same as above only providing commit message inline
git commit -am "<commit message>" --> add files from working directory to staging area and commits to local repository with commit message (will only add files listed by git ls-files, i.e. new files will not be added)
git push origin <branchName> --> pushing local repository to remote repository
File manipulation commands
git ls-files --> lists all files controlled by git
git mv <oldFileName> <newFileName> --> rename a file
git mv <oldDirName/fileName> <newDirName/> --> move a file to another directory
Log/history commands
git log --> show commit log history
git log --abbrev-commit --> same as above with shortened commit sha1
git log --oneline --> same as above with one line per commit
git log --oneline --graph --decorate --all --> will create ASCII graph for history (mostly visual when branching and merging)
git log --since="time statement" --> limit the history for time since "time statement" (e.g. git log --since="3 days ago")
git log -- <fileName> --> limit history to specific file
Aliasing
git config --global alias.<myAlias> '<git command without 'git' leading command> --> create an alias, note that git keyword should be omitted (e.g. git config --global alias.hist 'log --oneline --graph --decorate --all')
Tagging
git tag <myTag> --> add a lightweight tag to current commit
git tag --list --> list all tags
git tag --delete <myTag> --> delete a tag
git tag -a <myTag> --> add an annotated tag to current commit
git tag -a <myTag> -m "<tag description>" --> same as above with inline description message
Show commands
git show --> show last commit in current branch
git show <commit hash> --> show specific commit
git show <myTag> --> using tag as reference in other git command, in this case will show changes done on commit with
specific tag
Diff commands
git diff --> diff between working directory and staging area
git difftool --> same as above only using the configured difftool
git [diff|difftool] HEAD --> diff between working directory and local repository (last commit)
git [diff|difftool] --staged HEAD --> diff between staging area and local repository (last commit)
git [diff|difftool] -- <fileName> --> diff a single file