; ikamy.ch

Git Version Software Lynda GIT by Kevin Skoglund

  1. Config
  2. Initialize Starting
  3. log
  4. Diff
  5. Delete Rename Move
  6. Checkout
  7. gitignore file
  8. Branch
  9. Stash
  10. remote
  11. alias
  12. SSH key
«back

Configuration

GIT to see which branch we are cmd prompt in the project dir but windows already includes it PS1 is the file where config for command prompt
__git_ps1
We have 3 git on a system , user and project System located in c :git\etc\gitconfig
config –system
Project
git config
User home .gitconfig To configure on user we can locate in C:\User\Kamran
    git config –global user.name  “Kamran Nafisspour” 
git config –global user.email “nafisspour@bluewin.ch”
to add in config tell which editor to use and color
    git config –global core.editor “notepad.exe”
        git config –global color.ui true
    
to see config
git config –list
specific
git config user.name
or
git config user.email
inside user
.gitconfig
to see file content
 cat .gitconfig
help
    git help
    git help log or man git–log (unix)
    
«back

Initializing a repository

–ls –la (Unix) .git or dir (Window) Project to start tracking get in folder
git init
file .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”

«back

log

will show all the commit
git log
git log help
limit 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

Diff

statut working file - staging - repository
 git status
to see modification in staging before committing
git diff
to see staged diff compare with repository
git diff ––staged
see diff in dif format one line
git diff ––color–words filename.txt
 minus(–) + shit + s + return  to get full long line

«back

Delete

Delete file from explorer ,when seeing in staged as delete then to delete in repository
git add/rm filename
then 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.txt
rename 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.txt
move to other place directory firstdir but you can also rename it at same time
git mv first_file.txt firstdir/new_file.txt
«back

checkout

so if we want to get a file from repository back to working dir. use –– will ensure to stay on current branch
git checkout –– filename.txt 
to 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.txt 
in 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.txt 
so 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.txt 
if 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 f3b8da8c035641a62f67c94ff
we 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 f3b8da8c035641a62f67c94ff
mixed move pointer and changed staged but not wrkg dir.
git reset ––mixed f3b8da8c035641a62f67c94ff
hard reset all including working dir. all the commit afterwards will be lost
git reset ––hard f3b8da8c035641a62f67c94ff

to git remove file from being send to rep n test run f forces only on unstaged items it will remove it from the working dir caution permanent delete
git clean –n
git clean –f
«back

gitignore

for git to ignore files to be tracked in the repository a file .gitignore and ensure we commit the file can use regular expression or *.php or negation !index.php (do not ignore) ignore a all file in dir assets/videos github ignore file or github .gitignore suggestion ignore file globally not just a project and we have the file be anywhere. Create as a above in user .gitignore_global and all element to exclude cat file to see
 git config ––global core excludesfiles c:/user/kamran/.gitignore_global  
geet 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
«back

Branches

to see branches
git branch
to create branch
git branch newbranch
to switch branches
git checkout branchname
to switch and add a branch at the same time
git checkout –b newbranch 
We 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 ––merged
to rename a branch –m or ––move
git branch –m oldbranch newbranch
to 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 branchdelete
Now 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


        


        


        



    
«back

Stash

Stash is file that we can save temporary without to commit and we can save at a later stage not part of stagind or repository. If we make a change on branch for ex, it save and our repository and wrk directory previous state.
git stash save “message here”  
to see stash list will return with stash@{0} Stash is available also we switch branch
git stash list
will 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
«back

Github remote –github kamy333

push to upload to github creates the same branch in github At same time git put a copy locally in a branch origin/master which will be synchronized with github fetch to pull down from github eg other ppl change download go to branch origin/master and we can merge it if we want. So generally speaking, the process that you go through when you're working with a remote, is that you'll do your commits locally, then you'll fetch the latest from the remote server, get your origin branch in sync, then merge any of the new work you did into what just came down from the server and then push the result back up to the remote server.
In github create a repository free for public- to give a list of all remote
git remote
with more info
git remote –v
to remove a remote + nameof remote
git remote rm origin
To 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.git
to 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 master
if you did not use –u and you want to track it
git branch ––upstream branchname origin/branchname 
to see remote branch
git branch –r
to see both remote and local
git branch –a
to 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 ikamych
to 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 master
but since it is a trackin branch just use. we can sse then in github and origin/master
git push
so 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 origin
if we have only only 1 repository. Fetch often as it give latest github rep and see if any change was done.
git fetch
to check to repository as in github
git log ––oneline origin/master
git log ––oneline origin/branchname
will show remote
git branch –r
so 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/master
We have the possibility to fetch and merge in 1 cmd
git pull 
if there is remote branch create locally and will start tracking
git branch branchname origin/branchname
reminder create a branch and checkout –b
git branch –b branchname origin/branchname 
to delete a remote branch
git push origin ––delete branchname
Enabling collaboration
«back

Alias

use alias if you want to use keyboard shortcut command. It should be set in the global config setting. here some example double quotes if there is space “ commit -a” Status
git config ––global alias.st status
checkout
git config ––global alias.co checkout
commit checkin
git config ––global alias.ci commit
branch
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

SSH key

To have connection to github and not having to type your username and password over and over Setting SSH
to change remote between https and SSH