================================= Source Code Repository Servers ================================= => In a project multiple developers will develop the code from different location. => Developers may work from different locations. => We are going face below challenges when we have developers from different locations 1) How to integrate all the team members code at one place ? 2) How to monitor code changes happening in the project ? - who - when - why - what => To handle above 2 problems we can use "Source Code Repository servers". => Below softwares we can use as source code repository servers 1) SVN (outdated) 2) Clear Case (outdated) 3) GIT HUB 4) BIT BUCKET ======== Git Hub ======== => Git Hub is a cloud platform which is used to maintain source code repositories for our projects. => Git Hub will provide monitored access for source code repositories - who modified - when modified - why modified - what modified Note: GIT we will use as a client s/w to communicate with git hub repos. =================== Environment Setup =================== 1) Create account in www.github.com (free of cost) 2) Download & Install 'git client' software in our system URL : https://git-scm.com/downloads 3) Open Git bash and configure your name and your email using below commands $ git config --global user.name "your-name" $ git config --global user.email "your-email" Note: Configuring name and email is just one time process in git bash. $ git config --list =============================== What is Git Hub Repository ? =============================== => Repository is a place where we can store project source code / files. => For every project one git hub repository will be created by DevOps team. 1) Public Repo (anybody can see & you choose who can commit) 2) Private Repo (you choose who can see & who can commit) @@ Git Hub Repo URL : https://github.com/ashokitschool/01-canara-bank-app.git => Project team members will connect with git repository using its URL. Note: Team members will use git client software to connect with repository and they will perform operations in git hub repo.. ================== Git Architecture ================= 1) working tree 2) staging area 3) local repo 4) central repo ================ Git Commands ================ git clone : to download central repo to local system. $ git clone git status : display working tree status (staged and un-staged) red-color-file-name : not added to staging area green-color-file-name : added to staging area git add : Add files to staging area $ git add $ git add . git commit : Commit only staged files to local repo $ git commit -m git push : publish local commits to central repo git log : to display commit history git pull : download only latest changes from central repo to working tree. git rm : to remove file git rm Note: After 'git rm' execution we need to execute commit and push to delete file from central repo. ======================== What is git conflict ? ======================== => When we are merging central repo changes with working tree then we may get git conflict problem. => If two persons working on same file then we may get conflicts problem. Note-1: When we execute 'git pull' command there is a chance of getting conflicts. Note-2: When conflict occurs we need to resolve it and we need push changes to central repo without any conflict. =================================== Q) how to remove git local commits =================================== => Using 'git reset' command we can remove local commits. => Git Reset we can do in 2 ways 1) soft reset 2) hard reset => soft reset means only local commit will be deleted and file changes will be there in staging area. $ git reset --soft HEAD~1 => hard reset means local commit will be deleted and file changes also will be deleted from working tree. $ git reset --hard HEAD~1 ============================================ Q) how to revert git central repo commits ============================================ => Using 'git revert' command we can revert code changes from central repo. $ git revert Note: After git revert execution we need execute git push. ================ What is Git Gui ================ => It is a desktop tool to perform git operations. => Execute below command in working tree to open git gui $ git gui ============== Git Branches ============== => Assume that in our project 15 developers available => All 20 developers are divided into multiple teams 1) Dev Team (5 members) 2) R & D Team (5 members) 3) Prod Support Team (5 members) => When multiple teams working on same repo then project delivery will become very difficult. Note: As all teams integrating code changes in central repo we can't deliver particular team related code changes to client. => To make our project delivery process simple, we need to maintain multiple branches in one git hub repo. Ex: main develop feature research release .... => By using git branches, multiple teams can work paralelly and we can make our project delivery process simple. $ git clone $ git checkout $ git clone -b ======================== What is pull request ? ======================== => It is used to merge changes from one branch to another branch. ex: merge develop branch changes to main branch =========================== What is .gitignore file ? =========================== => It is used to specify files and folder to skip from git operations. ex: .settings .classpath .project target/ ======================== git pull vs git fetch ======================= git pull : download central repo changes to working tree directley git fetch : download central repo changes to local repo only. To bring local repo changes to working tree we need to use 'git merge' command. git pull = git fetch + git merge =========================== What is git cherrypick ? =========================== => It is used to merge pariticular commit from one branch to another branch based on commit id. $ git cherry-pick ====================== What is git fork ? ====================== => It is used to copy someone's git repo into our git hub account. ================================ What is branching strategy ? ================================ => It is the process of deciding which team should use which branch in git repo for code integration in the project. Note: DevOps team will define branching strategy for the project. a) main --> final code base b) develop ---> enhancements & change requests (CR) c) qa -------> bug fixing activities d) research ---> R & D team work e) release ---> code freezing purpose ====================== What is code freeze ? ====================== => When there is a production deployment then we will lock branch to stop code commits. so that we can make delivery process simple. Note: If we don't go for code freeze due to last minute commits existing fucntionality may brake and it may effect on delivery process. ==================== what is git stash ? ==================== => 'git stash' is a powerful Git command that allows you to temporarily save your uncommitted changes without committing them to the repository. ## usecase :: 9:00 AM IST ----> Assigned one task for me (JIRA-101) --- i am working on that task --- few changes completed (i need another 4hrs to complete the task) 2:00 PM IST --> assigned high priority task for me (JIRA-102) stop 101 and complete 102 first and push once 102 changes pushed then continue with 101 .. # save working tree changes to temporary area $ git stash # get stashed changes back to working tree $ git stash apply ======================== git merge vs git rebase ======================== git merge : Combines changes from one branch into another by creating a new merge commit. It will preseve commit history. git rebase : Moves or re-applies commits from one branch on top of another. It won't preserve commit history. ================================================= 1) git config 2) git init 3) git status 4) git add 5) git commit 6) git push 7) git restore 8) git reset 9) git revert 10) git log 11) git rm 12) git merge 13) git rebase 14) git cherry-pick 15) git clone 16) git pull 17) git fetch 18) git branch 19) git checkout 20) git stash 21) git stash apply 22) git help