- add file
git add [file name]
- add all
git add -A
- or add all file in this folder
git add .
- save addlist to history
git commit -m"[descriptive message]"
- see the history of commits
git log
- its less command in linux
q
->quite/[search]
and enter, n to next, N to Previous
- current status
git status
- can send argument, can send two or more
oneline
for see every commit in one linedecorate
show all the referencegraph
display ascii graph for branch structurep
patch, show the change of every commitstat
show the number of change of files
- can send option
- number to show the last-number, 2 for last 2 commit
after
orsince
for after certain time, after="yesterday", 30 minute ago, last tuesday, last week, 2 week ago, 3-15-16, 3/15/16before
oruntil
for commit before certain time, before="yesterday"author
author name, author="mohsen" all commit with author and email contain mohsengrep
search in commit messageS
search for string when add or remove in code, S"mat", better use with p arguman to see where usedG
search with regex for change in code dont need comma,-GMath|Random -> search for Math or Randomi
ignore case sensitiveno-merges
see without merge commit..
commit with range of references [ref1]..[ref2][file name]
the commit involve that files
git log --oneline --graph
git log -p -i -S"mat"
git log -3 -i --author="mohsen" README.md
git log -S"Math" --after="2 months ago" --online --stat
- use without argument or name show un-commit change
git diff
cashed
show difference between working directory and stashed
git diff --cashed
- can send branch name to see diff
git diff [branch name]
- can send file name
git diff origin/master README.md
- who modify the file and when
git blame [file name]
git reset --hard [name]
- save temporary the change added to history and clean the status
git stash
- unstash or come back the stash change
git stash apply
git clone http://github.com/mohsen12999/mycheat
git remote add origin [email protected]:fhfh/fgfg.git
git remote -v
- get the history from remote
git pull
- its equal to
git fetch && git merge
- send change to remote
git push
- add branch
git branch [new branch name]
- see all branch
git branch
- go to branch
git checkout [branch name]
- make and go to new branch
git checkout -b [new branch name]
- go to Previous branch
git checkout -
- merge branch to this branch [add feature of other branch to this branch]
git merge [branch name]
- delete branch
git checkout -d [branch name]
git rebase [branch name]
- use
i
for interactive mode
git rebase -i [branch name]
- combine all commit to one commit -> hold first to pick and change other to squash or only s, after save and exit you can add one commit message for all of that
- after this change must push with
f
or force flag
git push -f
< < < HEAD
our change
= = =
change come from server
> > >
- for start
git bisect
- mark this commit as bad commit
git bisect bad
- mark the good commit
git bisect good [commit id]
- git start searching for bad commit, answering them:
git bisect good
git bisect bad
- exit from bisect search
git bisect reset
- add tag
git tag v1.0.0
- see all tag
git tag
- push tag to remote
git push --tags
- annotate comment for tag with
a
, if not usem
it open in default editor
git tag -a v2.0.0 -m "tag message"
git config credential.helper store
- generate key
ssh-keygen -t rsa -b 4096 -C [email protected]
- add to ssh program
ssh-agent -s
- add rsa to ssh
ssh-add ~/.ssh/id_rsa
- copy rsa key to clip board
clip <~/.ssh/id_rsa
- go to github -> profile -> edit profile -> ssh keys -> add ssh key -> title: like the name of the computer or machine, past the key
- verify the key
ssh -T [email protected]
- in
.git/hooks
folder, there is some sample files, for run you must make file with out sample - for example in file
.git/hooks/pre-commit
, run test and lint before test
#!/bin/bash
npm test && npm run lint
- after that make file executable
chmod +x .git/hooks/pre-commit
- if one of them failed, we can not commit
- this setting just use locally and cant send to remote repository
- save in
.gitconfig
file in home directory
git config --global user.name 'mohsen shabanian'
- config default editor
git config --global core.editor vim
- add alias
git config --global alias.graph 'log --graph --oneline'
-- see all config list
git config list
- make
.gitignore
file and file name like.DS_Store
for mac orThumbs.db
for windows - for remove tracked file that ignore but added before:
git rm --cached [filename]
- we can make
.gitignore_global
in home directory for ignore file in all the place and define it in.gitconfig
git config --global core.excludesfile ~/.gitignore_global
-
git flow is great for a release-based software workflow.
-
Getting Started instead of
git init
git flow init
- Creating a feature branch
git flow feature start feature_branch
- Finishing a feature branch
git flow feature finish feature_branch
- Release Branches
git flow release start 0.1.0
- Finishing a Release Branches
git flow release finish '0.1.0'
- Hotfix Branches
git flow hotfix start hotfix_branch
- Finishing a Hotfix Branches
git flow hotfix finish hotfix_branch
- more info on Gitflow Workflow
- Egghead: practical-git-for-everyday-professional-use