git- fast-control-system

git :

Duraimurugan SK
8 min readMar 23, 2022

git is a free and openSource distributed version control system. It is designed to handle everything from small to very large projects with speed and efficiency. It is a tool to manage your source code history.

why use git :

git is a DevOps [ is a set of practices that combines software development (Dev) and IT operations (Ops)] tool used for source code management. The open-source version control system is used to handle small and very large projects efficiently. It is used to track changes in the source code enabling multiple developers to work together on non-linear development.

Before git learns beginners:

Before starting with Git, let us know what is Version Control. Version Control is the management of changes to documents, computer programs, large websites, and other collections of information.

git installation steps:

How to Install Git on Linux:

  1. To install Git run the following command:
sudo apt install git

2. If you see an error, consider running the following command before you install Git for Ubuntu:

sudo apt update
sudo apt install libz-dev libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext cmake gcc

setting up for GIT:

git config — global user.name “Your Name”
git config — global user.email “youremail@domain.com

We can display all of the configuration items that have been set by typing:

git config --listOutput
user.name=Your Name
user.email=youremail@domain.com
...

Working with local repositories:

git init:

This command turns a directory into an empty Git repository. This is the first step in creating a repository. After running git init, adding and committing files/directories is possible.

# make directory a git repository
$ git init
Initialized empty Git repository

git add:

Adds files in the to the staging area for Git. Before a file is available to commit to a repository, the file needs to be added to the Git staging area. There are a few different ways to use git add, by adding entire directories, specific files, or all unstaged files.

$ git add <file or directory name>
# To add all files not staged:
$ git add .

git commit:

Record the changes made to the files to a local repository. For easy reference, each commit has a unique ID and Adding a commit message helps to find a particular change or understanding the changes.

# Adding a commit with message
$ git commit -m "Commit message in quotes"

example

$ git commit -m "My first commit message"
[SecretTesting 0254c3d] My first commit message
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 homepage/index.html

git status:

git status will return the current working branch. If a file is in the staging area, but not committed, it shows with git status.

git status

example

$ git status
On branch SecretTesting
Untracked files:
(use "git add <file>..." to include in what will be committed)

homepage/index.html

# Message when files have been not been committed (git commit)
$ git status
On branch SecretTesting
Your branch is up-to-date with 'origin/SecretTesting'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

new file: homepage/index.html

# Message when all files have been staged and committed
$ git status
On branch SecretTesting
nothing to commit, working directory clean

git config:

With Git, there are many configurations and settings possible. git config is how to assign these settings. Two important settings are user user.name and user.email. These values set what email address and name commits will be from on a local computer. With git config, a — global flag is used to write the settings to all repositories on a computer. Without a — global flag settings will only apply to the current repository that you are currently in.

$ git config <setting> <command># Running git config globally
$ git config --global user.email "my@emailaddress.com"
$ git config --global user.name "Brian Kerr"

# Running git config on the current repository settings
$ git config user.email "my@emailaddress.com"
$ git config user.name "Brian Kerr"

git branch:

To determine what branch the local repository is on, add a new branch, or delete a branch.

# Create a new branch
$ git branch <branch_name>

# List all remote or local branches
$ git branch -a

# Delete a branch
$ git branch -d <branch_name>

git checkout:

To start working in a different branch, use git checkout to switch branches.

# Checkout an existing branch
$ git checkout <branch_name>

# Checkout and create a new branch with that name
$ git checkout -b <new_branch>

git merge:

git merge combines the changes from one branch to another branch. For example, merge the changes made in a staging branch into the stable branch.

# Merge changes into current branch
git merge <branch_name>

git revert:

The revert command will create a commit that reverts the changes of the commit being targeted. You can use it to revert the last commit.

git revert <commit to revert>
git revert

Working with remote repositories

git remote:

To connect a local repository with a remote repository.

# Add remote repository
$ git remote <command> <remote_name> <remote_URL>

# List named remote repositories
$ git remote -v

example

# Adding a remote repository with the name of beanstalk
$ git remote add origin git@account_name.git.beanstalkapp.com:/acccount_name/repository_name.git

# List named remote repositories
$ git remote -v
origin git@account_name.git.beanstalkapp.com:/acccount_name/repository_name.git (fetch)
origin git@account_name.git.beanstalkapp.com:/acccount_name/repository_name.git (push)

git clone:

To create a local working copy of an existing remote repository, use git clone to copy and download the repository to a computer.

$ git clone <remote_URL>

git pull:

To get the latest version of a repository run git pull. This pulls the changes from the remote repository to the local computer.

$ git pull <branch_name> <remote_URL/remote_name>

example

# Pull from named remote
$ git pull origin staging
From account_name.git.beanstalkapp.com:/account_name/repository_name
* branch staging -> FETCH_HEAD
* [new branch] staging -> origin/staging
Already up-to-date.

# Pull from URL (not frequently used)
$ git pull git@account_name.git.beanstalkapp.com:/acccount_name/repository_name.git staging
From account_name.git.beanstalkapp.com:/account_name/repository_name
* branch staging -> FETCH_HEAD
* [new branch] staging -> origin/staging
Already up-to-date.

git push:

Sends local commits to the remote repository. git push requires two parameters: the remote repository and the branch that the push is for.

$ git push <remote_URL/remote_name> <branch>

# Push all local branches to remote repository
$ git push —all

example

# Push a specific branch to a remote with named remote
$ git push origin staging
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (5/5), 734 bytes | 0 bytes/s, done.
Total 5 (delta 2), reused 0 (delta 0)
To git@account_name.git.beanstalkapp.com:/acccount_name/repository_name.git
ad189cb..0254c3d SecretTesting -> SecretTesting

# Push all local branches to remote repository
$ git push --all
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 373 bytes | 0 bytes/s, done.
Total 4 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To git@account_name.git.beanstalkapp.com:/acccount_name/repository_name.git
0d56917..948ac97 master -> master
ad189cb..0254c3d SecretTesting -> SecretTesting

Advanced Git Commands

git stash:

To save changes made when they’re not in a state to commit them to a repository. This will store the work and give a clean working directory.

# Store current work with untracked files
$ git stash -u

# Bring stashed work back to the working directory
$ git stash pop

example

# Store current work
$ git stash -u
Saved working directory and index state WIP on SecretTesting: 4c0f37c Adding new file to branch
HEAD is now at 4c0f37c Adding new file to branch

# Bring stashed work back to the working directory
$ git stash pop
On branch SecretTesting
Your branch and 'origin/SecretTesting' have diverged,
and have 1 and 1 different commit each, respectively.
(use "git pull" to merge the remote branch into yours)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified: index.html

no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (3561897724c1f448ae001edf3ef57415778755ec)

git log:

To show the chronological commit history for a repository. This helps give context and history for a repository. git log is available immediately on a recently cloned repository to see history.

# Show entire git log
$ git log

# Show git log with date pameters
$ git log --<after/before/since/until>=<date>

# Show git log based on commit author
$ git log --<author>="Author Name"

example

# Show entire git log
$ git log
commit 4c0f37c711623d20fc60b9cbcf393d515945952f
Author: Brian Kerr <my@emailaddress.com>
Date: Tue Oct 25 17:46:11 2016 -0500

Updating the wording of the homepage footer

commit 0254c3da3add4ebe9d7e1f2e76f015a209e1ef67
Author: Ashley Harpp <my@emailaddress.com>
Date: Wed Oct 19 16:27:27 2016 -0500

My first commit message

# Show git log with date pameters
$ git log --before="Oct 20"
commit 0254c3da3add4ebe9d7e1f2e76f015a209e1ef67
Author: Ashley Harpp <my@emailaddress.com>
Date: Wed Oct 19 16:27:27 2016 -0500

My first commit message

# Show git log based on commit author
$ git log --author="Brian Kerr"
commit 4c0f37c711623d20fc60b9cbcf393d515945952f
Author: Brian Kerr <my@emailaddress.com>
Date: Tue Oct 25 17:46:11 2016 -0500

Updating the wording of the homepage footer

git rm:(remove)

Remove files or directories from the working index (staging area). With git rm, there are two options to keep in mind: force and cached. Running the command with force deletes the file.

# To remove a file from the working index (cached):
$ git rm --cached <file name>

# To delete a file (force):
$ git rm -f <file name>

# To remove an entire directory from the working index (cached):
$ git rm -r --cached <directory name>

# To delete an entire directory (force):
$ git rm -r -f <file name>

git rebase:

Rebasing is the process of moving or combining a sequence of commits to a new base commit. Rebasing is most useful and easily visualized in the context of a feature branching workflow. The general process can be visualized as the following:

$git rebase <branch name>#If there are some conflicts in the branch, resolve them, and perform below commands to continue changes:$git status
#It is used to check the status,
$git rebase --continue

git merge:

To merge branches locally, use git checkoutto switch to the branch you want to merge into. This branch is typically the main branch. Next, use git mergeand specify the name of the other branch to bring into this branch.

$git checkout main
$git merge <branch name>
Merging Branches to Remote Repository
$git push --set-upstream origin <branch name>
Merging Main into a Branch
$git checkout <branch name>
$git merge main

************************Thanks To All******************************

--

--