GIT - bdbenu/Notes GitHub Wiki
=> Project contains multiple developers
=> Developers will be working from different locations
Problem-1 : How to integrate all the developers code at once place
Problem-2 : How to monitor/track code changes
- who
- when
- what
- why
=> To resolve above problems we will use Version Control softwares
=> We have several version control softwares
- SVN (outdated)
- GitHub
- Bitbucket
=> Git Hub is a cloud platform
=> 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
Note: For every project one github repository will be created.
-> Git Repository will provide monitored access (it will track our code changes)
-
Create account in github
URL : www.github.com
-
Download and install git client software
-
Configure your name and email in git bash.
$ git config --global user.name "Ashok"
$ git config --global user.email "[email protected]"
-
Working tree
-
Staging area
-
Local Repository
-
Central Repository
-
Create git repo (public)
-
Copy script from git repo and execute it in git bash
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 init : To initialize working tree
git status : To check working tree status (staged + unstaged)
git add : To add files to staging area
$ git add <filename>
$ git add .
git restore : To unstage the files + To discard file changes
# unstage the file (when it is added to staging)
$ git restore --staged <file-name>
# discard file changes (when it is in unstaged)
$ git restore <file-name>
git commit : Send files from staging area to local repo
$ git commit -m <msg>
git log : To check commit history
git push : Send files from local repo to central repo.
git clone : To download central repo to working tree
$ git clone <repo-url>
git pull : To take latest code changes from central repo to our working tree.
git rm : To remove the files
$ git rm <file-name>
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 commit -m <msg>
$ 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
=> Multiple teams will be working on the project paralelly 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 seperate code bases for multiple teams working in the same project.
=> Using git branches multiple teams can work paralelly.
=> In project, one team work shouldn't effect other teams work. We can resolve this issue using git branches concept.
=> In git repo, we will have branches like below
- 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 clone
$ git clone -b
$ git branch
$ git checkout
=> It is used to merge changes from one branch to another branch.
=> This file is used to specify which files & folders we don't want to commit to git repo.
ex : target folder, .project, .settings, .classpath etc...
=> Go to git repo => Go to settings => Go to collobarators => Add team member email and send invitation
Note: Invited member will get email to become collaborator.
Once inviation got accepted, colloborator can commit to our repo.
=> 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.
-
When we execute 'git pull' command there is a chance of getting conflicts.
-
When we are merging branches then there is a chance of getting conflicts.
=> It is used to store working tree changes to temp area and make working tree clean.
$ git stash
$ git stash apply
9:00 AM => Task-320 assigned for you // your started working on that task // few code changes already done in m1() method // you are in middle of the task
Note: Task is not completed
12:30 PM => Manager assigned Task-321 and told high pririoty
first complete Task-321 and then work on Task-320
This is task is related to m2 ( ) method.
When we try to commit m2 () changes m1() changes also will be committed because both methods are in the same file.
Bu 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 directley. 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 pull = git fetch + git merge
=> It is used to remove the changes we have commited from remote repository based on the commit id.
$ git revert
=> 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.
-
Management will decide repository server (Ex: github or bitbucket)
-
Management will decide branching strategy (which team should use which branch)
-
Development Team should send request to create git repo to DevOps team with manager approval.
-
DevOps team will manage user permissions on the repository.
-
Once git repo created we can create branches based on our requirement.
-
As a developer we will perform code integration + branch merging with pull requests.
-
When there is production deployment, DevOps team will make code freeze (remove write permissions on the repository)
Note: If we don't have write permission to git repo then we need to raise request to devops team to get access with your manager approval.
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.
=> BitBucket software developed by Atlasian company.
=> Bitbucket is used to maintain/manage source code repositories like github
=> For Bitbucket repositories we can use 'git' as client.
-
What is version control & why ?
-
Git Hub Introduction
-
Git Setup
-
Git Architecture
-
Git Repository creation (public & private)
-
Git bash commands
- 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 stash apply - git branch - git checkout - git revert
-
Working git gui
-
Working with git branches & pull requests
-
Git branching strategy
-
Adding Collobarators
-
Git conflicts
-
Git forking
-
Real-Time workflow
-
BitBucket