Git is a version control system of distributed nature that is used to track changes in source code during software development. It is used for coordinating work among developers in project. It can also be used to track changes in any set of files. The main objectives of Git are speed, data integrity, and support for distributed, non-linear workflows.
GitHub is a Git repository hosting service, plus it adds many of its own features. GitHub provides a Web-based graphical interface. It also provides access control and several collaboration features, basic task management tools for every project.
a) With the Version Control System(VCS), all the team members can work freely on any file at any time. VCS gives the flexibility to merge all the changes into a common location.
b) All the previous versions and variants are neatly packed up inside the VCS. We can request any version at any time as per our requirement and we will have a snapshot of the complete project right at hand.
c) Whenever we save a new version of our project, our VCS requires a short description of the changes that we have made. Additionally, we can see what changes are made in the file’s content. This helps us to know what changes have been made in the project and by whom and when those changes were made.
d) A distributed VCS like Git allows all the team members to have a complete history of the project so if there is a breakdown in the central server you can use any of your teammate’s local Git repository.
git clone
git status
git add --a
git commit -m 'msg'
git push
git pull
git log
git rm
git checkout
git fetch
git branch
Git Repository is a place where we will store/maintain our project source code.
We can 2 types of repositories in git hub
1) Public Repository (Every body can see, we choose who can commit)
2) Private Repository (We choose who can see and who can commit)
Note: For every project we will create one git repository.
Cloning in a GitHub repository is nothing but taking project from git hub central repository to our local repository.
> git clone
git commit -m 'msg' is used to write commit message
Note: Commit message represents why we are commiting this change to git repository
GIT stash is used when there is a need of storing the current changes available in working tree to temporary space and work on other changes due to priority. Once priority changes completed then user can get old changes back from temporary space.
git status command is used to list down stated and un-staged files in working tree
staged file means it is eligible for commit
un-staged file means which is modified in local but not eligible for commit.
Note: To commit changes we have to stage it using git add
The following are the few advantages of using the GitHub repository;
a) Provides high availability
b) Easy Collaboration tool
c) Distributed version control
d) Quality open source project
e) Security, Git is designed specially to maintain the integrity of source code
GitHub is a fast tool and ‘C’ language makes this possible by reducing the overhead of runtime associates with the higher programming language.
The “Git push” command is used for pushing changes from local repository to central repository.
The “Git pull command is used for taking latest changes from central repository to local repository
Using git reset command we can un-stage the file
When we do commit in git it will generate one unique id with 40 characters length to differentiate one commit with another commit. Using commit-id we can identify what all changes committed to git repository.
To remove a file from git repository we can use "git rm" command.
When we release code to SIT or UAT or PROD we will lock the branch so that nobody can commit changes to that branch so that existing functionality or code will not be disturbed.
Merging changes from one branch to another branch is called as branch merging. For example we have done changes in develop branch and tested then we can merge the code from develop branch to master branch.
Note: We will use "pull request" for branch merging.
Yes, while merging code from one branch to another branch i have faced conflicts and i resolved conflicts then i merged my code from develop branch to master branch.
git stash drop command is used to remove all stashes available in git.
The Git log command is used to find the history of commits happend in git repository. Using that history we can identify who, when, why & what changed in git repository.
When we are pushing/merging changes to git repository there is a chance of getting git conflicts.
Git can handle most merges on its own with automatic merging features. A conflict arises when two separate branches have made edits to the same line in a file, or when a file has been deleted in one branch but edited in the other. Conflicts will most likely happen when working in a team environment.
The following steps will resolve conflict in Git
Identify the files that have caused the conflicts
a) Make the necessary changes in the files so that conflict does not arise again
b) Add these files to staging using git add . command
c) Commit the changed file(s- using "git commit" command
To compare files we can use "git diff" command
Git uses your username to associate commits with an identity. The git config command can be used to set your user-name and email-id.
Suppose you want to give a username and email id to associate a commit with an identity so that you can know who has made a particular commit
git config –global user.name “Your Name”: This command will add a username.
git config –global user.email “Your E-mail Address”: This command will add an email id.
We have several client software's to interact with git repository
Git bash
Git GUI
Git Tortoise etc.
There are approaches to handle this scenario
Approach-1 : Remove or edit the changes in the file in a new commit and then push it to the remote repository. This is the most obvious way to fix an error. Once we have made required changes then commit that file to the remote repository using : git commit -m “commit message”Also, you can create a new commit that undoes all changes that were made in the bad commit.
Git pull command pulls new changes or commits from a particular branch from your central repository and updates your target branch in your local repository.
Git fetch is also used for the same purpose but it works in a slightly different way. When you perform a git fetch, it pulls all new commits from the desired branch and stores it in a new branch in your local repository. If you want to reflect these changes in your target branch, git fetch must be followed with a git merge.
Your target branch will only be updated after merging the target branch and fetched branch. Just to make it easy for you, remember the equation below:
Git pull = git fetch + git merge
"git clone" is used to take entire project from central repository to local repository
"git pull" is used to take only latest changes/commits from central repository to local repository