What is GIT?
Git is one of the most popular open-source version control systems. It is very fast and is the most used Version Control System. It allows programmers to track changes at different stages of the project.
Git is a distributed version control system that enables a team of developers to collaboratively work on a single project; a copy of the project is made available on everyone’s local computer.
How Does GIT work?
Git allows us to track changes. When using GIT the code moves through 3 stages:
● Working Directory(local) is where you do all your changes to the file.
● A staging area is where you can track changes made in the working directory.
● Repository (Usually Remote) is where GIT stores all the changes permanently.
To install Git you can follow the instructions on: https://git-scm.com/downloads
Else you can check if Git is already installed by running “git version”
You can check the current configurations by running git config --global --list
Additionally, you can configure the username and email.
-You can clone the Git repository as a working copy or initialize an empty repository.
-You can modify the working copy by adding/editing files.
-If necessary, you can also update the working copy by taking other developers' changes.
-You can review and commit changes. If everything is fine, then you push the changes to the repository.
● Git init
The git init command creates a new Git repository. It can be used to convert an existing, unversioned project to a Git repository or initialize a new, empty repository.
Add something to the repository or create a new file.
● Git add
Git add. OR git add <filename> adds the changes to the staging area to be committed.
● Git commit
Git commits –m 'commit message' creates a commit out of the changes that have been added. ( commit is the term used for saving changes)
● Git status
The git status command displays the state of the working directory and the staging area. It lets you see what changes have been staged, what haven't, and which files haven’t been tracked by Git. The status output does not show you any information regarding the committed project history.
You can optionally add the -sb flag to view the short form of the same output
● Git log
The Git Log tool allows you to view information about previous commits that have occurred in a project. These commits are shown in reverse chronological order (the most recent commits first). Use git log --oneline to list a short summary of all commits.
A branch in Git is simply a lightweight movable pointer to one of these commits. The default branch name in Git is master that allows one to try out new ideas. If the idea doesn’t work, throw away the branch no need to undo changes to master. If the idea works, then it can be merged with the master branch. There is only ONE working directory.
● Git branch
This lists all the branches and the current branch you are on.
● Git branch <branchName>
This creates a new branch with the given name.
Use git checkout -b <branch> to create a new branch with the specified name and switch to it.
● Git checkout <branchName>
This switches the branch to the given name.
● Git diff <branchName>
GIT diff is a multi-use Git command, when it is executed it runs a diff function on Git data sources. The git diff command is often used along with git status and git log to analyze the current state of a GIT repo. It displays the changes that were introduced. It compares the current branch with the given branch name.
● Git merge
Merging is Git's way of putting a forked history back together again. The git merge command lets you take the independent lines of development created by the git branch and integrate them into a single branch.
● Git clone
GIT clone is a Git command-line utility that is used to target an existing repository and create a clone or copy of the target repository.
● Git push
The git push command is used to upload local repository content to a remote repository. Pushing is how you transfer commits from your local repository to a remote repo. Remote branches are configured using the git remote command.
Syntax - git push origin <branchName to push to remote
● Git pull
The git pull command is used to fetch and download content from a remote repository and immediately update the local repository to match that content. Once the content is downloaded, git pull will enter a merge workflow. A new merge commit will be created and HEAD updated to point at the new commit.
Resolving Merge conflicts - GitLive
When two or more people are working on the same file there can be cases where merge conflicts can happen. There are lots of ways and tools to resolve such conflicts. GitLive is an extension that allows programmers to resolve conflicts even before they occur. GitLive is supported across most IDEs. There are two ways to resolve the conflicts using GitLive:
● Live: See others' local changes in the gutter of your editor and get notified the moment you make a conflicting change.
● Patch: View diffs of other contributors' local files and cherry‑pick individual lines, files, or complete working copies.
GIT offers other features as well like codeshare where you can make voice and video calls directly from your editor, and codeshare to see each other's cursors. You can also see when your fellow developers are online and which repos, branches, and files they are working on.
We at Fibonalabs, work towards building secure and scalable solutions based on in-trend technologies. Here, we reduce time to market and offer a better performance of web and mobile applications by leveraging the power of the latest tools and techniques. Join our tribe to learn and grow with us.