├── Git.pdf ├── README.md └── images ├── Three States of git project.png ├── branches.png ├── git diff.png ├── git reset.png ├── merge.png └── push committed.png /Git.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkassm/Git/092a0449c3972be46413c7b0a48dd30dd03a8e8c/Git.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Git 2 | 3 | [![Build Status](https://travis-ci.org/joemccann/dillinger.svg?branch=master)](https://github.com/aboelkassem/Git/blob/master/Git.pdf) 4 | 5 | **The Content** 6 | 7 | - [Version Control System](#version-control-system) 8 | - [Three Stages of a File](#three-stages-of-a-file) 9 | - [Three States of git project](#three-states-of-git-project) 10 | - [Command Line](#command-line) 11 | * [Tracked files by git has three stages](#tracked-files-by-git-has-three-stages) 12 | * [Untracked Files](#untracked-files) 13 | * [Push committed changes to Origin Master branch](#push-committed-changes-to-origin-master-branch) 14 | * [Track commits and see the history of previous commits](#track-commits-and-see-the-history-of-previous-commits) 15 | * [Commit Message](#commit-message) 16 | * [Remove and Move Files](#remove-and-move-files) 17 | * [Branches](#branches) 18 | * [Merge](#merge) 19 | * [Git stash](#git-stash) 20 | * [Git reset](#git-reset) 21 | 22 | ## What is Git? 23 | 24 | ##### Version Control System 25 | - Software designed to record changes to files over time 26 | - Ability to revert back to previous file version or project version 27 | - Compare changes made to files from one version to another 28 | - Version control any plain text file not just source code 29 | 30 | ## Three Stages of a File 31 | 32 | - Committed 33 | mean that files is stored safely in repo of the project 34 | - Modified 35 | when make changes in last commit, just introduced new changes but has committed them yet 36 | - Staged 37 | when changes finished and ready to commit. 38 | 39 | ## Three States of git project 40 | ![](https://github.com/aboelkassem/Git/blob/master/images/Three%20States%20of%20git%20project.png) 41 | 42 | ## Command Line 43 | 44 | > [github-git-cheat-sheet.pdf](https://github.github.com/training-kit/downloads/github-git-cheat-sheet.pdf) 45 | 46 | > [git-docs-all-commends](https://git-scm.com/docs/git#_git_commands) 47 | 48 | ### Tracked files by git has three stages 49 | + Committed 50 | Unmodified changes from the last commit snapshot, when make changes to these files 51 | content then moved to modified stage 52 | + Modified 53 | Changes made to files since last commit snapshot, when you satisfied with changes and 54 | stage them for commit will move to staged area 55 | + Staged 56 | Changes marked to be added into the next commit snapshot, now can commit it to origin 57 | repositories 58 | 59 | ### Untracked Files 60 | 61 | 62 | mean that git sees a new file that didn't exist in her last commit. and add them to stage are to 63 | be ready to commit 64 | 65 | 66 | ``` 67 | $ git status 68 | $ git status --short 69 | ``` 70 | > This commend show the status of tracked and untracked files for your local and remote origin repository 71 | ``` 72 | $ git diff 73 | $ git diff --staged 74 | ``` 75 | 76 | this commend answer the following two questions 77 | 78 | > 1- What changes have I staged that are ready to be committed? 79 | 80 | > 2- What changes have I made but not yet staged? 81 | 82 | ![](https://github.com/aboelkassem/Git/blob/master/images/git%20diff.png) 83 | ### Push committed changes to Origin Master branch 84 | ![](https://github.com/aboelkassem/Git/blob/master/images/push%20committed.png) 85 | 86 | After Commit push these files from local project to remote origin repository on github 87 | 88 | ``` 89 | $ git push origin master 90 | $ touch # create a new file 91 | ``` 92 | ### Track commits and see the history of previous commits 93 | ``` 94 | $ git log 95 | $ git log -1 96 | $ git log --oneline 97 | $ git log --stat 98 | $ git log --patch 99 | ``` 100 | ### Commit Message 101 | 102 | There are guidelines are followed to commit message to be useful and helpful to other 103 | contributors there are blog that had a lot of information about these seven rules in [this blog](https://chris.beams.io/posts/git-commit/) 104 | 105 | > 1- Separate subject from body with a blank line 106 | > 2- Limit the subject line to 50 characters 107 | > 3- Capitalize the subject line 108 | > 4- Do not end the subject line with a period 109 | > 5- Use the imperative mood in the subject line 110 | > 6- Wrap the body at 72 characters 111 | > 7- Use the body to explain what and why vs. how 112 | ### Remove and Move Files 113 | 114 | ``` 115 | $ git rm # remove file from project and git untracks it 116 | $ git rm --cached # only git untracks it but keeping in local repo 117 | $ git mv # to rename file 118 | $ git reset head # to stop tracking this file 119 | ``` 120 | ### Branches 121 | 122 | branches to organize your code to adding new features or working separately from base code 123 | and merge this after finishing or creating pull request. especially working with multiple collaborators to get a copy of version and work in it and merge it This tool is animate to understanding branching in git 124 | ``` 125 | $ git checkout # working/switching on new_branch and commit to it 126 | $ git checkout -b # creating and working/switching on new_branch and commit to it 127 | $ git checkout master # working/switching in master brance 128 | $ git branch # list of branches do you have 129 | $ git branch # create new branch but don't switch to it (checkout) 130 | $ git branch -m # rename a branch 131 | $ git branch -d # delete a branch 132 | $ git branch -D # Force delete a branch if this branch have commits do not merged yet 133 | ``` 134 | ![](https://github.com/aboelkassem/Git/blob/master/images/branches.png) 135 | 136 | ### Merge 137 | 138 | merge command it to merge branches with all it's commits and working files to master branch. if you are contributor you can make branches and working at them and merge them as pull request to your master branch and send it to origin master branch as also pull request to be merged 139 | ![](https://github.com/aboelkassem/Git/blob/master/images/merge.png) 140 | 141 | ### Git stash 142 | git stash temporarily shelves (or stashes) changes you've made to your working copy. The git stash command takes your uncommitted changes (both staged and unstaged), saves them away for later use, and then reverts them from your working copy 143 | ``` 144 | $ git stash # saving our working directory and staging area as a secert box 145 | $ git stash list # get list a stashes or progress chages that we've stashed 146 | $ git stash pop # get the chages/files from stash to dropped back into his working directory 147 | ``` 148 | ### Git reset 149 | git reset allow us move commits from history back into our working or staging area 150 | ![](https://github.com/aboelkassem/Git/blob/master/images/git%20reset.png) 151 | ``` 152 | $ git reset --soft 153 | $ git reset --mixed 154 | $ git reset --hard 155 | ``` 156 | -------------------------------------------------------------------------------- /images/Three States of git project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkassm/Git/092a0449c3972be46413c7b0a48dd30dd03a8e8c/images/Three States of git project.png -------------------------------------------------------------------------------- /images/branches.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkassm/Git/092a0449c3972be46413c7b0a48dd30dd03a8e8c/images/branches.png -------------------------------------------------------------------------------- /images/git diff.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkassm/Git/092a0449c3972be46413c7b0a48dd30dd03a8e8c/images/git diff.png -------------------------------------------------------------------------------- /images/git reset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkassm/Git/092a0449c3972be46413c7b0a48dd30dd03a8e8c/images/git reset.png -------------------------------------------------------------------------------- /images/merge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkassm/Git/092a0449c3972be46413c7b0a48dd30dd03a8e8c/images/merge.png -------------------------------------------------------------------------------- /images/push committed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkassm/Git/092a0449c3972be46413c7b0a48dd30dd03a8e8c/images/push committed.png --------------------------------------------------------------------------------