ranjithsrt1

Ranjith srt

Posted on September 2, 2024

Git

Git is a powerful version control system which used to manage the code across multiple users and track changes across different versions.

Installation:

Download and install GIT from the below path

https://git-scm.com/download/win
Enter fullscreen mode Exit fullscreen mode

Once installed, Git can be used as a version control system through various commands.
You can configure Git for a specific folder on your computer, allowing you to manage all changes to existing files and the addition of new files within that folder

Basic commands:

1. git init:
Enter fullscreen mode Exit fullscreen mode

This will initialize new repository in the current directory. This also creates .git directory and store all version control information.

2. git config:
Enter fullscreen mode Exit fullscreen mode
git config --global user.name "Ranjith "
Enter fullscreen mode Exit fullscreen mode
git config --global user.mail "ranjith201099@gmail.com"
Enter fullscreen mode Exit fullscreen mode
3. git status
Enter fullscreen mode Exit fullscreen mode

Shows the current status of working area like staged, untracked and unstaged.

4. git add
Enter fullscreen mode Exit fullscreen mode

add changes from working directory to the staging area, preparing them to commit.

To add specific file: git add "filename.py"
Enter fullscreen mode Exit fullscreen mode
To add all changes git add .
Enter fullscreen mode Exit fullscreen mode
5. git commit
Enter fullscreen mode Exit fullscreen mode
git commit -m "<message>"
Enter fullscreen mode Exit fullscreen mode

Commits the staged changes with descriptive mesage

6. git log
Enter fullscreen mode Exit fullscreen mode

Displays the list of commit history for the repository.
It will show commit id, author, dates and commit changes
Creating a branch

git branch <branch_name> - to create branch
Enter fullscreen mode Exit fullscreen mode
git checkout <branch_name> - to switch to the new branch
Enter fullscreen mode Exit fullscreen mode
git branch -b <branch_name> 

Enter fullscreen mode Exit fullscreen mode

to create and switch to branch
git branch - to view all the branches (current branch will be highlighted with asterisk)

Merge a branch:
Enter fullscreen mode Exit fullscreen mode

Once completed work on a branch and want to integrate it into another branch (like master), merging comes to place.

It means all the changes we have made in <branch_name> will be merged with master branch.
First, switch to the branch you want to merge into: git checkout master
Enter fullscreen mode Exit fullscreen mode
Then, use git merge <branch_name> to merge your branch.
Enter fullscreen mode Exit fullscreen mode
Deleting branch
Once the code changes in <branch_name> merged into <master> branch, we might need to delete branch.
Enter fullscreen mode Exit fullscreen mode
use git branch -d <branch_name> to delete branch
Enter fullscreen mode Exit fullscreen mode

C:\Users\ranji\OneDrive\Desktop\New folder>git --help


usage: git [-v | --version] [-h | --help] [-C <path>] [-c <name>=<value>]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           [--config-env=<name>=<envvar>] <command> [<args>]


These are common Git commands used in various situations:


start a working area (see also: git help tutorial)
   clone     Clone a repository into a new directory
   init      Create an empty Git repository or reinitialize an existing one


work on the current change (see also: git help everyday)

   add       Add file contents to the index
   mv        Move or rename a file, a directory, or a symlink
   restore   Restore working tree files
   rm        Remove files from the working tree and from the index


examine the history and state (see also: git help revisions)

   bisect    Use binary search to find the commit that introduced a bug
   diff      Show changes between commits, commit and working tree, etc
   grep      Print lines matching a pattern
   log       Show commit logs
   show      Show various types of objects
   status    Show the working tree status

grow, mark and tweak your common history

   branch    List, create, or delete branches
   commit    Record changes to the repository
   merge     Join two or more development histories together
   rebase    Reapply commits on top of another base tip
   reset     Reset current HEAD to the specified state
   switch    Switch branches
   tag       Create, list, delete or verify a tag object signed with GPG

collaborate (see also: git help workflows)

   fetch     Download objects and refs from another repository
   pull      Fetch from and integrate with another repository or a local branch
   push      Update remote refs along with associated objects

'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
See 'git help git' for an overview of the system.


Enter fullscreen mode Exit fullscreen mode

Image description

Image description

💖 💪 🙅 🚩
ranjithsrt1
Ranjith srt

Posted on September 2, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Git
git Git

September 2, 2024