;
__git_ps1We have 3 git on a system , user and project System located in c :git\etc\gitconfig
config –systemProject
git configUser home .gitconfig To configure on user we can locate in C:\User\Kamran
git config –global user.name “Kamran Nafisspour”to add in config tell which editor to use and color
git config –global user.email “nafisspour@bluewin.ch”
git config –global core.editor “notepad.exe” git config –global color.ui trueto see config
git config –listspecific
git config user.nameor
git config user.emailinside user
.gitconfigto see file content
cat .gitconfighelp
git help git help log or man git–log (unix)
git initfile .git in the project is created config file can be used but do not use others dot do all or filename in quotes
git add .
git commit –m “message here”if only modifications not if delete or new file so we can commit without going through stage it will take all in working dir
git commit –am “message here”
git log
git log helplimit no of commit most recent in log or expressed in a date
git log –n 5
git log ––since=2012-06-15
git log ––until=2012-06-15
git log ––author=“Kamran Nafisspour”regular expression
git log ––grep=“init”see all logs summarized
git log ––oneline«back
git statusto see modification in staging before committing
git diffto see staged diff compare with repository
git diff ––stagedsee diff in dif format one line
git diff ––color–words filename.txt
minus(–) + shit + s + return to get full long line
git add/rm filenamethen we do regular commit if we want to delete the file from the folder and adds to stage as delete process and the we do commit after
git rm filename.txtrename if changed from explorer will need to add new and rem, git will figure is a rename and the we commit. 2nd way ,we can rename from git files and will put it stagged
git mv first_file.txt new_file.txtmove to other place directory firstdir but you can also rename it at same time
git mv first_file.txt firstdir/new_file.txt«back
git checkout –– filename.txtto bring back a file modified that is staged not yet committed file and want unstaged. the working will still keep the change
git reset HEAD filename.txtin repository how to undo changes or commits. possible to change the latest commit bring the modified in stage. Can be used also if we want to change the message onlyS
git commit –– amend –m “message here”to bring back a version old version of a file do checkout with the SHA 10 first and it will bring it into staged and recommit if you want.
git checkout 6ae98716b64286eb1 –– filename.txtso we could re.commit git commit with message
commit git commit -m “6ae98716b64286eb1 message here”or discard by unstaged reset and then checkout by taking latest version in repository.
or unstaged / git reset HEAD filename.txt
checkout / git checkout -- filename.txtif we want to revert a commit take first 10 SHA. note did not work for me failed maybe becs a texteditor should pop out I needed it to recommit normal. ok for simple revert otherwise use cmd merge eg file moved or renamed
git revert f3b8da8c035641a62f67c94ffwe can undo recent commit by moving header and start out from there. Soft move pointer but not staged and wrk dir use SHA to where ou want to point
git reset ––soft f3b8da8c035641a62f67c94ffmixed move pointer and changed staged but not wrkg dir.
git reset ––mixed f3b8da8c035641a62f67c94ffhard reset all including working dir. all the commit afterwards will be lost
git reset ––hard f3b8da8c035641a62f67c94ff
git clean –n
git clean –f«back
git config ––global core excludesfiles c:/user/kamran/.gitignore_globalgeet git to ignore file before .gitignore was created. so we must untracked. it will delete in my repo, leave copy in wrkg dir . takes it off staging process (rm without cached delete both)
git rm ––cached filename.txt
git branchto create branch
git branch newbranchto switch branches
git checkout branchnameto switch and add a branch at the same time
git checkout –b newbranchWe can compare branch and tree-ish ^ mean the previous commit of that branch
git diff new_feature..shorten_title^And to see branches that hve the latest commit of other branches. First checkout in which branch you want to be then
git branch ––mergedto rename a branch –m or ––move
git branch –m oldbranch newbranchto delete branch –d or ––delete. need to be on a another branch to del. in case some change uncommitted on branch use capital D
git branch –d branchdeleteNow if we finished our branch project and want to merge to a parent. so i need to be in the receiver branch to merge so use checkout and type the sending branch Ensure we have the clean directory-
git merge branchname
git stash save “message here”to see stash list will return with stash@{0} Stash is available also we switch branch
git stash listwill show summary change
git stash show stash@{0}to see more p=patch
git stash show –p stash@{0}to retrieve stash and will bring back in wrkg dir can use pop or apply pop put in wkg dir and remove from stash - apply will keep a copy in stash without reference will pull out first one
git stash pop stash@{0}to delete a stash
git stash drop stash@{0}to delete all stash once. caution it is destructive
git stash clear
git remotewith more info
git remote –vto remove a remote + nameof remote
git remote rm originTo configure with address shown github https example origin is alias and we can use others. info store .git/config
git remote add origin https://github.com/kamy333/projectname.gitto push into github can be a branch. github may change. Will need to provide username and password after. Creates a new branch –u to keep have reference with remote , withjot mean we just want to put there
git push –u origin masterif you did not use –u and you want to track it
git branch ––upstream branchname origin/branchnameto see remote branch
git branch –rto see both remote and local
git branch –ato bring down a project github for ex. go to the place you want to download. find the link in gihub the path. you can name the directory name at the end eg ikamych if you don't want default. –b if you wanted a branch (in github admin we can specify which branch we want) Note by downloading it tracks the remote
git clone https://github.com/kamy333/projectname.git ikamychto push a change into remote . after doing all the commit as usual. Now this in our master but not in the local copy of remote origin/master To check
git diff origin/master..master
git push origin masterbut since it is a trackin branch just use. we can sse then in github and origin/master
git pushso now if want to see the change but as another user as eg collaborator. Let's say I downloaded in another folder. so need to do a fetch to retrieve. will bring back master (origin/master) and branch (origin/branchname) if any
git fetch originif we have only only 1 repository. Fetch often as it give latest github rep and see if any change was done.
git fetchto check to repository as in github
git log ––oneline origin/master
git log ––oneline origin/branchnamewill show remote
git branch –rso now if we want to bring the remote origin/master local into our master we need to merge. Need to be in the receiver(master) to receive from (origin/master)
git merge origin/masterWe have the possibility to fetch and merge in 1 cmd
git pullif there is remote branch create locally and will start tracking
git branch branchname origin/branchnamereminder create a branch and checkout –b
git branch –b branchname origin/branchnameto delete a remote branch
git push origin ––delete branchnameEnabling collaboration
git config ––global alias.st statuscheckout
git config ––global alias.co checkoutcommit checkin
git config ––global alias.ci commitbranch
git config ––global alias.br branch
git config ––global alias.dfs “diff ––staged &rdquo
git config ––global alias.dfs “diff ––staged ”
git config ––global alias.logg “––graph ––decorate ––oneline ––abbrev–commit ––all ”«back