Git
Version 0.01
Important commands
• cd <directory>
• cd ~
• cd ..
• pwd # print working directory
• ls # list the files in this directory
• diff -u test.txt test2.txt ( fc in windows)
• Primitive source control
• You create new copy each time
• Version source control
• Keep track of code history
Who uses version control ?
• Google docs
• Wekipedia
• Dropbox
• Git
• Subversion (SVN)
Explain commit
When to commit?
• By function
Lets use dropbox, it automates the process
noob.. !
Key concepts
• Commit
• Blob
• diff
• Branch
• Merge
• Repository
Subversion vs git
Config username and email
• git config --global user.email "w-elatrash@hotmail.com"
• git config --global user.name ”Wasim Alatrash"
Two ways to start working with git
• You have a project on your local machine
• You want to clone a project from repository
• Github
• GitLab
• bitbucket
• Remote
• Cloning
• Clone
• Demo: Clone a project
Cloning/forking
• Git clone [https link]
• Git log: list latest commits ( q to skip/quit)
• Git log –stat (show updated files)
• git checkout <commit hash> (to return to specific commit)
• Demo: fork a repository >update > push > pull
• Cd ..
• rm -rf [Directory]
• Git clone [directory]
• git remote –v
• Show attached connections to current repository
Creating git repository
• Mkdir [directory name]
• Git init
• Git status (shows changed files since last commit)
• https://choosealicense.com/
• Vim LICENSE
• Escape then :wq to save file changes
• Vim README.md
• # headline
vim
• Vim ”filename” -> create file and edit it using vim
• Rm [filename] -> remove a file
• Do changes to file
• Git diff
• Git add
• Git diff ( no Is empty)
• Then you have to use git log –p to see the diff
• Git diff –staged (to get the diff between staged and repository)
• Git reset HEAD [filename] ( to remove a file from staging area)
• Git diff [commit hash] [commit hash]
• Git show [commit hash]
Staging area
• Working directory
• Staging area (index)
• Repository
• Git add
• to add to staging area
• git reset HEAD <file>
• To remove from staging area
Ignore Files
• Passwords and secret files
• Build files
• Third party libraries that you can reinstall it using library manager
• Demo
• Vim .gitignore
• *.html
• /dir1
• Filename.txt
• Global ignore files
• https://github.com/github/gitignore
• git config --global core.excludesfile (see where its stored)
• Vim [directory/filename]
Viewing history
• Git log
• Git log -4
• Git log –oneline
• Git log –graph
• Git log –oneline –graph –all
• Git shortlog (seperated by auther)
• Git log –author=“wasim” ( filter by auther name)
• Git log –grep=“idea” ( filter by keyword in commit messages)
• Git log – [filename] ( get all commits related to filename)
Branching
• By default: it creates master branch
• What is the branch ? Label for particular commit, and it keep moving
while you are commiting
• Commit hash help commits refer to its parent
• When to Use Branches?
• git branch [mybranch] ( create a branch)
• Git branch ( view branches )
• git checkout [mybranch] ( switch to other branch)
• git branch -d [mybranch] (delete a branch)
• * is the current branch
Merging
• Git referance for 3 points, last 2 commits in both branchs and the
commit they splited from. And calc the diff then merge the diff.
• Git merge [mybranch] ( merge mybranch to current branch)
• Git merge –no-ff [mybranch] (to prevent fast forward merge)
• There are no staging area in github
• Only related commits will be pushed to github
• Create a Repository
• Init the rep with readme will create one commit, don’t do that if you already
have git project stored locally and you want to push it
• Git remote
• Git remote –v
• Git remote add <name> // usually called origin
• Git pull <remote> <branch-name>
• Why might you want to always pull changes manually rather than having Git
automatically stay up-to-date with your remote repository?
• Forking
• It make it easy to share you project with otherone without pulling the code >
push to new repository > then let the other developer do pull again from the
new remote
• Fork is not git command, it’s github innovation
• Git clone
• Git clone add remote for you automatically
• Add contributors from settings
• Get fetch origin master
• Get merge master origin/master

11 git version control

  • 1.
  • 2.
    Important commands • cd<directory> • cd ~ • cd .. • pwd # print working directory • ls # list the files in this directory • diff -u test.txt test2.txt ( fc in windows)
  • 3.
    • Primitive sourcecontrol • You create new copy each time • Version source control • Keep track of code history
  • 4.
    Who uses versioncontrol ? • Google docs • Wekipedia • Dropbox • Git • Subversion (SVN)
  • 5.
  • 6.
  • 7.
    Lets use dropbox,it automates the process noob.. !
  • 8.
    Key concepts • Commit •Blob • diff • Branch • Merge • Repository
  • 9.
  • 10.
    Config username andemail • git config --global user.email "w-elatrash@hotmail.com" • git config --global user.name ”Wasim Alatrash"
  • 11.
    Two ways tostart working with git • You have a project on your local machine • You want to clone a project from repository
  • 12.
  • 13.
    • Remote • Cloning •Clone • Demo: Clone a project
  • 14.
    Cloning/forking • Git clone[https link] • Git log: list latest commits ( q to skip/quit) • Git log –stat (show updated files) • git checkout <commit hash> (to return to specific commit) • Demo: fork a repository >update > push > pull • Cd .. • rm -rf [Directory] • Git clone [directory] • git remote –v • Show attached connections to current repository
  • 15.
    Creating git repository •Mkdir [directory name] • Git init • Git status (shows changed files since last commit) • https://choosealicense.com/ • Vim LICENSE • Escape then :wq to save file changes • Vim README.md • # headline
  • 16.
    vim • Vim ”filename”-> create file and edit it using vim • Rm [filename] -> remove a file
  • 17.
    • Do changesto file • Git diff • Git add • Git diff ( no Is empty) • Then you have to use git log –p to see the diff • Git diff –staged (to get the diff between staged and repository) • Git reset HEAD [filename] ( to remove a file from staging area) • Git diff [commit hash] [commit hash] • Git show [commit hash]
  • 18.
    Staging area • Workingdirectory • Staging area (index) • Repository • Git add • to add to staging area • git reset HEAD <file> • To remove from staging area
  • 19.
    Ignore Files • Passwordsand secret files • Build files • Third party libraries that you can reinstall it using library manager • Demo • Vim .gitignore • *.html • /dir1 • Filename.txt
  • 20.
    • Global ignorefiles • https://github.com/github/gitignore • git config --global core.excludesfile (see where its stored) • Vim [directory/filename]
  • 21.
    Viewing history • Gitlog • Git log -4 • Git log –oneline • Git log –graph • Git log –oneline –graph –all • Git shortlog (seperated by auther) • Git log –author=“wasim” ( filter by auther name) • Git log –grep=“idea” ( filter by keyword in commit messages) • Git log – [filename] ( get all commits related to filename)
  • 22.
    Branching • By default:it creates master branch • What is the branch ? Label for particular commit, and it keep moving while you are commiting • Commit hash help commits refer to its parent • When to Use Branches?
  • 23.
    • git branch[mybranch] ( create a branch) • Git branch ( view branches ) • git checkout [mybranch] ( switch to other branch) • git branch -d [mybranch] (delete a branch) • * is the current branch
  • 24.
    Merging • Git referancefor 3 points, last 2 commits in both branchs and the commit they splited from. And calc the diff then merge the diff. • Git merge [mybranch] ( merge mybranch to current branch) • Git merge –no-ff [mybranch] (to prevent fast forward merge)
  • 25.
    • There areno staging area in github • Only related commits will be pushed to github • Create a Repository • Init the rep with readme will create one commit, don’t do that if you already have git project stored locally and you want to push it • Git remote • Git remote –v • Git remote add <name> // usually called origin
  • 26.
    • Git pull<remote> <branch-name> • Why might you want to always pull changes manually rather than having Git automatically stay up-to-date with your remote repository? • Forking • It make it easy to share you project with otherone without pulling the code > push to new repository > then let the other developer do pull again from the new remote • Fork is not git command, it’s github innovation
  • 27.
    • Git clone •Git clone add remote for you automatically • Add contributors from settings • Get fetch origin master • Get merge master origin/master

Editor's Notes

  • #8 - Manual vs auto Commits: you should use manual to make logically right commits when you finish feature or complete update - Dropbox don’t save history forever, it’s available for 1 month, then it will be removed!
  • #15 Git log: list latest commits rm -rf [Directory] means force the recursive removal of someDirectory
  • #16 أي ديركتري بتقدر تحولو ل قيت بروجكت.. اللي بصير انو القيت بتضيف فولدر مخفي اسمو دوت قيت جوات الفولدر
  • #17 The Vim editor is a modal editor. That means that the editor behaves differently, depending on which mode you are in. The two basic modes are called Normal mode and Insert mode. In Normal mode the characters you type are commands. In Insert mode the characters are inserted as text.
  • #18 git diff بجيب الفرق مبين الستيجنق اريا والوركنق ديركتري.. فلو انا ضايف كل الملفات اللي اتعدلت على الستيجنق اريا .. ما هيكون في أي اختلافات
  • #19 لما بعمل add انا بضيف فايلات على الستيجنق اريا وبعدها بروح بعمل كوممت فبتنتقل من الستيجنق للريبوزتري.. فتخيل معي لو كنت عامل عدة تعديلات وبدك تضيف كل تعديل في كوميت لوحد.. فبتعمل اد للملفات اللي الها علاقة وبعدين كومت ومن ثم نفس الكرة للتعديل التاني..