Github Notes 829
Github Notes 829
txt
========================================================
Source Code Repository Tools (or) Version Control Softwares
========================================================
-> All developers code should be stored at one place (Code Integration Should Happen)
-> To integrate all the developers source code at one place we will use Source Code Repository
Softwares
================================================
Advantages with Source code repository sofwares
================================================
1) All the developers can connect to repository server and can integrate the code
- Who
- When
- Why
- What
==============
Repository Tools
==============
SVN (outdated)
Git Hub
BitBucket
=================================
Environment Setup to work with Git Hub
=================================
3) Once installation completed, right click on the mouse and verify git options display (If git
options displaying our git client installation completed successfully)
=====================
Working with GitHub
=====================
Note: Repository is used to store project source code. Every Project will have one repository
-> When we create a repository, unique URL will be generated with Repository Name (i.e Repo URL)
Ex: https://github.com/ashokitschool/hdfc_bank_app.git
-> All the developers will connect to repository using Repository URL
https://ashokitech.com/uploads/notes/1804657772_1703993336.txt 1/7
4/9/24, 12:31 AM ashokitech.com/uploads/notes/1804657772_1703993336.txt
1) public repository
2) private repository
-> Public Repository means everybody can access but we can choose who can modify our repository
-> Private Repository means we will choose who can access and who can modify
====================
Working with Git Bash
====================
-> Git Bash we can use as Git Client software to perform Git Operations
-> Right Click on Mouse and choose "Open Git Bash Here"
==================================================
Configure Your Email and Name in Git Bash with Commands
==================================================
Note: email and name we will configure only for first time.
Un-Staged Files : The files which are modified but not added for commit
$ git add .
https://ashokitech.com/uploads/notes/1804657772_1703993336.txt 2/7
4/9/24, 12:31 AM ashokitech.com/uploads/notes/1804657772_1703993336.txt
$ git push : To push changes from git local repository to git central repository
==================================================
Steps to push code to github central repository
==================================================
1) Create one public repository in git hub (take github repo url)
$ touch Demo.java
$ git add .
8) Push file from git local repository to git central repository using 'git push' command
$ git push
Note: If you are doing 'git push' for first time it will ask to enter your github account
password.
--------------------------------------------------------------------------------------------------
----------------
Note: Git bash will ask our password only for first time. It will save our git credentials in
Credential Manager in Windows machine.
-> Go to Credential Manager -> Windows Credentials -> Select Github -> We can modify and delete
saved credentials from here
--------------------------------------------------------------------------------------------------
----------------
-> When we do git commit then it will geneate a commit-id with 40 characters length
-> From this commit-id it will display first 7 characters in git hub central repository
==================================================
Steps to commit Maven Project to Github Repository
==================================================
https://ashokitech.com/uploads/notes/1804657772_1703993336.txt 3/7
4/9/24, 12:31 AM ashokitech.com/uploads/notes/1804657772_1703993336.txt
2) Create GitHub Repository
Note: After creating git repository, it will display set of commands to execute
$ git init
$ git add .
$ git commit -m 'commit-msg'
$ git branch -M main
$ git remote add origin <repo-url>
$ git push -u origin master
--------------------------------------------------------------------------------------------------
------------------
When we are working on one task suddenly we may get some other priority task.
Usecase
++++++++
-> ager assigned task id : 101
-> I am working on that task (i am in middle of the task)
-> Managed told that stop the work for 101 and complete 102 on priority.
-> Once 102 is completed then resume your work on 101
-> When manager asked me to start 102 task, i have already done few changes for 101
(partially completed)
-> We can't push partial changes to repository because with our partial changes existing
functionality may break.
-> We can't delete our changes because we have spent few hours of time to implement those changes
=> Git stash is used to save working tree changes to temporary location and make working tree
clean.
-> After priority work completed we can get stashed changes back using 'gitstash apply'
============
Git Branches
============
-> Branches are used to maintain seperate code bases for our project
main
develop
qa
release
research
-> To clone particular branch in git repo we will use below command
https://ashokitech.com/uploads/notes/1804657772_1703993336.txt 4/7
4/9/24, 12:31 AM ashokitech.com/uploads/notes/1804657772_1703993336.txt
==============
Branch Merging
==============
=> The process of merging changes from one branch to another branch is called as Branch merging
============================
Steps to do branch merging
============================
3) create new file in feature branch then commit and push to central repo
4) Go to central repository then create pull request to merge feature branch changes to main
branch
Note: Once feature branch changes are merged to main branch then we can delete feature branch (if
required)
=========================
What is .gitignore ?
=========================
-> This .gitignore is used to configure the files or folders which we want to ignore from our
commits
-> The files and folders which are not required to commit to central repository those things we
can configure in .gitignore file
Ex: In maven project, 'target' folder will be available which is not required to commit to central
repository. This we can configure in .gitignore file.
---------------------------------------.gitignore-------------------------------------------------
------
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
https://ashokitech.com/uploads/notes/1804657772_1703993336.txt 5/7
4/9/24, 12:31 AM ashokitech.com/uploads/notes/1804657772_1703993336.txt
!**/src/test/**/build/
=========================
git merge vs git rebase
==========================
=> These commands are used to merge changes from one branch to another branch
-> When we are working on particular sprint and we want to merge changes from one branch to
another branch then we will use 'git merge' command
-> Once sprint-1 is delivered then we want to take latest code of sprint-1 to start sprint-2
development. In this scenario we don't need commit history so we will use 'git rebase' command.
===========================
What is git pull command
===========================
-> pull command is used to take latest changes from repository to local
-> When we want to make some changes to code, it is always recommended to take git pull first then
start your changes.
Note: When we execute 'git pull' there is a chance of getting conflicts. We need to resolve the
conflict and we should push the code without conflicts.
==================
Git Hub Lab Task
==================
1) Create Maven Web Application
2) Add 'Spring-Core' dependency in project pom.xml file (www.mvnrepository.com)
3) Package maven project as war file using maven goal
4) Create Git repository in github / bitbucket (public repo)
5) Push maven project into github repo using gitbash
(target folder shouldn't be commited, add this in .gitignore file)
6) Make changes in pom.xml and push changes to github repo using git bash
7) Create 'feature' branch in git repo from main branch
8) Switch to feature branch from git bash
9) Make changes in 'feature' branch pom.xml file
10) Push changes to feature branch
11) Create pull request and merge 'feature' branch changes to 'main' branch
=======================
Git Hub Class Summary
========================
1) What is Source Code repository
2) Why we need source code repository
3) What are the source code repositories available
4) What is git hub
5) What is git
6) What is Repository
7) Public Repository vs Private Repository
8) Cloning Repository
9) Staged vs Unstaged vs Untracked File
10) Adding Files to Stating Area
11) Unstaging the files from staging
12) Discarding local changes
13) What is working tree
14) What is Local Repostiory
https://ashokitech.com/uploads/notes/1804657772_1703993336.txt 6/7
4/9/24, 12:31 AM ashokitech.com/uploads/notes/1804657772_1703993336.txt
15) What is Central / Remote Repository
16) Commit from working tree to local repo (git commit -m 'msg')
17) push from local repo to central repo (git push)
18) Taking latest code changes
19) push vs pull
20) What is conflict
21) How to resolve conflicts
22) What is branch in git hub
23) How to create branches
24) How to clone particular branch ( git clone -b <branch-name> <repo-url> )
25) how to switch to particular branch (git checkout <branch-name>)
26) How to merge branches
27) What is pull request
28) git merge vs rebase
29) what is .gitignore
30) Working with Bitbucket
git init
git help
git config
git clone
git status
git add .
git add <file-name>
git restore
git commit
git push
git pull
git log
git rm
git revert
git branch
git checkout
git fetch
git merge
git rebase
git stash
=======
BitBucket
=========
https://ashokitech.com/uploads/notes/1804657772_1703993336.txt 7/7