Comprehensive overview of GIT & GITHUB  Concepts

Comprehensive overview of GIT & GITHUB Concepts

Stages in GIT

  1. Working Directory:- In working directory, developers can make modification in files but its not marked as a part of git's versioning system as they will be present on local. This area is also known as "untracked" area of GIT.

  2. Staging Area:- The staging area is where you tell git start tracking and save the changes to git. Now the files are part of git versioning control but changes have not been committed yet. And If you are sure with your changes then you can use "git add" command to add them in staging area.

  3. Local Repository:- This is the final area where git permanently stores your changes. if you are ready to save the changes, commit them to the repository using the "git commit" command. The repository contains a complete history of all changes to your project, and its easily allow you to revert back to previous versions if needed.

  4. **Remote Repository:-**A remote in Git is a common repository that all team members use to exchange their changes. In most cases, such a remote repository is stored on a code hosting service like GitHub or on an internal server.

Git concepts for newcomers — Part 2: Git repository, working tree and  staging area | by Sébastien Dubois. | ITNEXT

GIT installation

Go to below link to download GIT CLI

Git website: git-scm.com

On command line: (where verb = config, add, commit, etc.)

git help verb.

GIT initial configuration:

• Set the name and email for Git to use when you commit:

git config --global user.name "ABC"

git config --global user.email

You can call "git config –list" to verify these are set. • Set the editor that is used for writing commit messages: git config --global core.editor nano • (it is vim by default)

GIT Repositories

To create a new local Git repo in your current directory: – git init

• This will create a .git directory in your current directory.

• Then you can commit files in that directory into the repo.

– git add filename – git commit –m "commit message"

• To clone a remote repository to your current directory:

– git clone url localDirectoryName

• This will create the given local directory, containing a working copy of the files from the repo, and a .git directory (used to hold the staging area and your actual local repo)

GIT Snapshots

•Centralized VCS like Subversion track version data on each individual file. • Git keeps "snapshots" of the entire state of the project.

– Each "checkin version" of the overall code has a copy of each file in it.

GIT tags

Tags assign a meaningful name with a specific version in the repository. Once a tag is created for a particular codebase even if you create a new commit, it will not be updated. Tagging is generally used to capture a point in history that is used for a marked version release (i.e. v1. 0.1). A tag is like a branch that doesn't change.

Clone

A local version of a repository, including all commits and branches using GIT. Changes made to the cloned repository cannot be merged with the original repository unless you are the collaborator or the owner of the repository.

Fork

creating a copy of the original repository on our GitHub account. Changes made to the forked repository can be merged with the original repository via a pull request.

Pull Requests

Its an event that discuss the changes introduced on a branch with reviews, comments, integrated tests .etc to another branch in GIT repository.

HEAD

It represents your current working directory, the HEAD pointer can be moved to different branches,tags or commits when using git cloudwatch.

GIT commits

• The first time we ask a file to be tracked, and every time before we commit a file, we must add it to the staging area. When we execute git commit, changes will be commited to repository and we will get commitid for each change.

git add Hello.java Goodbye.java

• It takes a snapshot of these files, adds them to the staging area.

• In Git, "add" means "add to staging area" so it will be part of the next commit.

• To move staged changes into the repo, we commit:

– git commit –m "commiting 1st change"

• To undo changes on a file before you have committed it:

– git reset HEAD -- filename (unstages the file)

– git checkout -- filename (undoes your changes)

All these commands are acting on your local version of repo.

Git Merge and GIT Rebase

Git Merge and Git Rebase are two ways of integrating changes from one branch into another in Git, but they have different implications for the resulting branch history. GIT Merge command simply combines changes from one branch into another branch.

We can merge the main branch into the feature branch using below command:

Or we can do it with single command as below:

Merging master into the feature branch

On the other hand, Git rebase moves the feature branch on the tip of the main branch, effectively incorporating all of the new commits in main. The major benefit of rebasing is that you get a much cleaner and linear project history.

git checkout feature

git rebase main

GIT RESET

The command is used undo the changes in the working directory and move back to the previous commit while discarding all the changes made after that particular commit.

$ git reset <commit_id>

GIT REVERT

It is same as git reset the only difference is that it will undo the last commit done by taking you back to the staged file before the commit .

$ git revert <commit_id>