├── Setup_repo_for_a_project.md ├── git_ignore_file.md ├── What_is_Version_Control_System.md ├── Revert_changes_on_git.md └── git_commands.md /Setup_repo_for_a_project.md: -------------------------------------------------------------------------------- 1 | # Create a git repository for Production ready code. 2 | 3 | ## Repository setup for a Project in the real-world 4 | 1. Create a private repository 5 | 2. Create 3 branches (Prod, Staging and Dev) 6 | 3. Add team as collaborators to this repository. 7 | 4. Enable SSH based authentication 8 | 5. Protect Master and staging branches 9 | 6. 1 approval needed to check-in code on staging branch and 2 approvals needed to check-in code on to Prod branch 10 | 7. Build and Deploy should be successful before check-in the code onto staging branch as well as onto Prod branch 11 | 12 | -------------------------------------------------------------------------------- /git_ignore_file.md: -------------------------------------------------------------------------------- 1 | # Compiled source # 2 | ################### 3 | *.com 4 | *.class 5 | *.dll 6 | *.exe 7 | *.o 8 | *.so 9 | 10 | # Packages # 11 | ############ 12 | # it's better to unpack these files and commit the raw source 13 | # git has its own built in compression methods 14 | *.7z 15 | *.dmg 16 | *.gz 17 | *.iso 18 | *.jar 19 | *.rar 20 | *.tar 21 | *.zip 22 | 23 | # Logs and databases # 24 | ###################### 25 | *.log 26 | *.sql 27 | *.sqlite 28 | 29 | # OS generated files # 30 | ###################### 31 | .DS_Store 32 | .DS_Store? 33 | ._* 34 | .Spotlight-V100 35 | .Trashes 36 | ehthumbs.db 37 | Thumbs.db 38 | -------------------------------------------------------------------------------- /What_is_Version_Control_System.md: -------------------------------------------------------------------------------- 1 | ### what is version control 2 | Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later. 3 | It allows you to revert selected files back to a previous state, revert the entire project back to a previous state, compare changes over time, see who last modified something that might be causing a problem, who introduced an issue and when, and more. 4 | Centralized Version Control Systems (CVCSs) were developed. These systems (such as CVS, Subversion, and Perforce) have a single server that contains all the versioned files, and a number of clients that check out files from that central place. 5 | In a DVCS (such as Git, Mercurial, Bazaar or Darcs), clients don’t just check out the latest snapshot of the files; rather, they fully mirror the repository, including its full history. 6 | 7 | -------------------------------------------------------------------------------- /Revert_changes_on_git.md: -------------------------------------------------------------------------------- 1 | # Revert changes on git 2 | 3 | ### Revert changes from working directory 4 | ```sh 5 | git restore 6 | or 7 | git checkout -- 8 | ``` 9 | - `Note: even you can remove changes manually. But if we have updated multiple files and don’t know which lines to remove this command really helps` 10 | 11 | ### Revert changes from Staging Area 12 | ```sh 13 | git restore --staged #to revert changes from Staging area to working directory 14 | git restore #to revert changes from working directory 15 | ``` 16 | 17 | ### Revert changes from Local Repository 18 | ```sh 19 | git reset HEAD~ # to revert changes from local repo to working directory 20 | git restore # to revert changes from working directory 21 | ``` 22 | 23 | ### Revert changes from Remote Repository 24 | 25 | We dont have direct way to do this. 26 | -------------------------------------------------------------------------------- /git_commands.md: -------------------------------------------------------------------------------- 1 | 2 | git init . 3 | git add 4 | git commit -m "Commit information" 5 | git status 6 | git log 7 | git remote add "remote_repo" // add remote repo to local system 8 | git clone // clone repo into local system 9 | git pull origin master 10 | git push origin master 11 | git checkout -- 12 | git checkout -- . 13 | git restore 14 | git restore . 15 | git checkout 16 | git checkout file // to get a file from previous commit 17 | git annotate 18 | git branch --set-upstream-to=origin/master master 19 | git reset HEAD~N (N is number of commits to revert) //revert commits on local repository 20 | git checkout 21 | git checkout HEAD~1 22 | 23 | git rebase -i HEAD~N (N is number of commits to squash) // to combain multiple comments as a single. 24 | git config --global user.name "USERNAME" 25 | git config --global user.email "USERNAME@EMAIL.COM" 26 | git commit -m "COMMIT_ID" 27 | git push origin master 28 | git remote add origin "GITHUB_REPO_URL" 29 | git add "" / git add . 30 | git commit -m "" 31 | git push origin 32 | git checkout -- // to revert changes from git working directory area 33 | git reset HEAD //unstage a file 34 | git checkout // move to previous commit 35 | git reset HEAD . //unstage all changes 36 | git checkout -- . 37 | git show 38 | git show HEAD 39 | git show HEAD~1 40 | git annotate 41 | git branch --set-upstream-to=origin/master master 42 | git branch // to create a new branch 43 | git checkout -b // to create new branch and switch to branch 44 | git merge 45 | git branch -d // to delete a branch --------------------------------------------------------------------------------