========= Git Hub ========= => Git is a version control software -> Git Hub is a platform which is used to store all the developers project source code at one place. -> In git hub, we can create repository to store project code. -> All the developers can connect to git hub repository for code integration. (Code Integration will become very easy) -> Using Git Hub repository we can monitor/track all code changes. - who modified - when modified - what modified - why modified =================== 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. =============================== 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. => We can create 2 types of repositories in git hub 1) Public Repo (anybody can see & you choose who can commit) 2) Private Repo (you choose who can see & who can commit) @@ Project Git Repo URL : https://github.com/ashokitschool/sbi_loans_app.git => Project team members will connect with git repository using its URL. ================== Git Architecture ================== 1) Working Tree 2) Staging Area 3) Local Repo 4) Central Repo (Remote) ================== Git Bash Commands ================== git init : Initialize working tree git status : display working tree status (staged and un-staged) git add : Add file(s) to staging area git add git add . git commit : Commit staged files to local repo git commit -m git push : publish local commits to central repo git restore : to unstage + to discard file changes git log : to display commit history 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. git clone : to download central repo to local git clone Ex: https://github.com/ashokitschool/01_products_api.git git pull : download only latest changes from central repo to local repo Note-1: When we use git pull command there is a chance of getting conflicts. Note-2: If 2 developers modify same file and same line of data then conflict will occur. We need to resolved and we need to commit and push without conflicts. ================ 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 =========================== What is .gitignore file ? =========================== => It is used to specify files and folder to skip from git operations. ex: .settings .classpath .project target/ ============== Git Branches ============== 20 developers available in the team development team => 5 ppl research & dev team => 5 ppl bug fixing team => 5 ppl prod support => 5 ppl => When multiple teams working on same repo then project delivery will become difficult. => To make our project delivery process simple, we need to maintain multiple branches in git hub repo. Note: For every team one git branch is recommended. => By using branches, multiple teams can work paralelly. main branch (Default) development team ===> develop branch bug fixing team ===> sit branch r & d team ===> research branch prod team ===> release branch ========= Lab Task ========= 1) Go to git hub repository and create develop branch from main branch 2) clone git repo (by default main branch will come) $ git clone 3) Switch from main to develop $ git checkout develop 4) create a file and push to develop branch 5) Create pull request and merge develop branch changes to main branch. ============================================================= git clone https://github.com/ashokitschool/01_products_api.git git clone -b develop https://github.com/ashokitschool/01_products_api.git ======================== 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 git stash ================== => It is used to save working tree changes in backup and make working tree clean. JIRA-101 story assigned to me @9 AM.. work started... few changes completed... i m in middle of that story.... @11 am, JIRA-102 assigned and it is very crictical now... => To complete JIRa-102 story first we need to stash 101 story related changes. => Once JIRA-102 story changes pushed then we can get 101 story changes back using 'git stash apply' command. =================================== Q) how to remove git local commits =================================== => Using git reset command we can undo local commits => Git Reset we can do in 2 ways a) soft reset b) hard reset => soft reset means only local commit will be deleted and file changes will be there in staging area. Ex : git reset --soft HEAD~1 => hard reset means local commit will be deleted and file changes also will be deleted from working tree. Ex : 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. Ex : git revert Note: After git revert execution we need execute git push. =========================== Q) what is git cherry-pick =========================== => When we use 'git merge' command by default all commits will merge from one branch to another branch. => If we want to merge specific commit from one branch to another branch then we can use 'git cherry-pick'. Ex : git cherry-pick ========================= Q) Git pull vs git fetch ========================= git pull : Download latest changes from central repo to working tree directley. git fetch : download from central repo to local repo only. note : To merge changes from local repo to working tree we can use 'git merge' command. git pull = git fetch + git merge ====================== Q) What is git fork ? ====================== => It is used to copy somebody's git repo into our git hub account. Note: When we want to work with open source projects then we can use git forking option.