GITHUB
GITHUB
===========================
- who
- when
- what
- why
- SVN (outdated)
- GitHub
- Bitbucket
=========
Git Hub
=========
=> Using git hub we can maintain source code repositories for the projects
=> Source code repos are used to store project source code at once place
-> Git Repository will provide monitored access (it will track our code changes)
==================
Environment Setup
==================
URL : www.github.com
URl : https://git-scm.com/download/win
3) Configure your name and email in git bash.
=================
Git Architecture
=================
1) Working tree
2) Staging area
3) Local Repository
4) Central Repository
=====================
=====================
Note: Git bash is a client to perform git operations with github repo
Note: When we execute git push for first it will ask for git account credentials/token.
Note: It will save our git account credentials in "Windows Credentials Manager". If we want to
connect with diff github account then we have remove those credentials.
====================
====================
$ git add .
git restore : To unstage the files + To discard file changes
git pull : To take latest code changes from central repo to our working tree.
Note: When we use 'git rm' command file will be deleted only in working tree. To remove that
file from central repo then we have to commit and push.
$ git push
=============================
=============================
=> Git gui will provide graphical user interface to perform git operations
=> To open git gui we can execute below command in our working tree
$ git gui
=============
Git Branches
=============
=> Multiple teams will be working on the project parallelly like below
- on going development
- bug fixing
- poc / r&d
- production support
=> When all these team members merging their code changes then it is very difficult to
differentiate which code changes are done by which team in repository.
******* To overcome this problem we will use git branches concept *********
=> Git branches are used to maintain separate code bases for multiple teams working in the
same project.
=> In project, one team work shouldn't effect other teams work. We can resolve this issue using
git branches concept.
- main (default)
- develop
- feature
- sit
- uat
- release ....
Note: We can use any name for the branch and we can create any number of branches in git
repo.
Note: When we use git clone we will get default branch (i.e. main)
$ git branch
# To switch branch
=============================
=============================
=====================================
What is .gitignore file in git repo ?
=====================================
=> This file is used to specify which files & folders we don't want to commit to git repo.
=======================================
=======================================
=> Go to settings
=> Go to collaborators
========================
========================
=> When we are merging central repo changes with local repo then we may get git conflict
problem.
=> If two persons working on same file then we may get conflicts problem.
=> When conflict occurs we have to resolve those conflicts and we have to commit without
conflicts.
============================
============================
=> It is used to store working tree changes to temp area and make working tree clean.
$ git stash
Usecase :
----------
9:00 AM => Task-320 assigned for you
When we try to commit m2 () changes m1() changes also will be committed because both
methods are in the same file.
But the requirement we need to commit only m2 () changes to central repo first. Here we can
use git stash commnad before starting m2 () method changes.
======================
======================
git pull : download latest code changes from central repo and merge with working tree directly.
There is a chance of getting conflicts here.
git fetch : download latest code changes from central repo to local repo. It will not merge
changes into working tree.
Note: After git fetch completed, we need to execute 'git merge' command to merge changes
from local repo to working tree.
=============
git revert
=============
=> It is used to remove the changes we have committed from remote repository based on the
commit id.
=> After executing git revert command it will open editor then press Esc + :wq to close the
editor.
=> After 'git revert' command execution we need to execute 'git commit + git push' to publish
revert operation to central repo.
=====================
=====================
=> forking means creating copy of other git user repository in our git hub account.
===================
Realtime workflow
===================
2) Management will decide branching strategy (which team should use which branch)
3) Development Team should send request to create git repo to DevOps team with manager
approval.
5) Once git repo created we can create branches based on our requirement.
6) As a developer we will perform code integration + branch merging with pull requests.
7) When there is production deployment, DevOps team will make code freeze
Note: If you have any confusion with git operations/branches/branching-strategy take team
members help.
Note: We need to be very careful when we are working with source code repositories because if
we do any mistake it will effect other team members work also.
=======================
=======================
=============================
=============================
=========
Summary
=========
3) Git Setup
4) Git Architecture
- git config
- git init
- git status
- git add
- git restore
- git commit
- git push
- git clone
- git pull
- git fetch
- git merge
- git rm
- git log
- git stash
- git branch
- git checkout
- git revert
14) BitBucket