Ad Code

Responsive Advertisement

Ticker

6/recent/ticker-posts

GIT-Professional-1

***GIT Official chat sheet:https://git-scm.com/docs

https://git-scm.com/docs

 ===================Git Config===================
1. Git configuration

Git config
Get and set configuration variables that control all facets of how Git looks and operates.

GIT Object types:
BLOB
Tree
Commit
Annotated Tag

Note: Each git commit having backed author name & email commit description (parent-optional)


Commit is a wrapper (around tree  object) which is there tree & each commit have diff SHA code

Simple set config username and email:
git config --global user.name "User name"
git config --global user.email "raj@gmail.com"

*To view the config list

git config --list

Set the name:
$ git config --global user.name "User name"

Set the email:
$ git config --global user.email "raj@gmail.com"

Set the default editor:
$ git config --global core.editor Vim

Check the setting:
$ git config -list
Git alias
Set up an alias for each command:
$ git config --global alias.co checkout
$ git config --global alias.br branch
$ git config --global alias.ci commit


git commit flow:


To view the files from working directory to the index area command is below u need to run git add .

git ls-files -s

after that you can commit the file git commit -m "first file change"
**Explore the commit messages:

git cat-file -p cae3

$ git cat-file -p cae3

tree 3766bcd572091203af9cf2ce582b9e5d40f38610

author shivasingam111 <shivasingam111@gmail.com> 1703058448 +0530

committer shivasingam111 <shivasingam111@gmail.com> 1703058448 +0530

first file change

to find size of a commit & type 
$  git cat-file -s cae3
200
 git cat-file -t cae3
commit

Working area ---> staging or index area --> GIT Repo

** to check the current state of project: git status
to add files into staging area                : git add file-name
write changes into the git repo             : git commit 
history of changes                                 : git log
checkout commit or branch                    : git checkout

other command git --> pull,push,fetch,clone

to view the commit history
=================================
$ git log
commit cae3477dfbd3400060038d58cdbd75fa929a5b7c (HEAD -> master)
Author: shivasingam111 <shivasingam111@gmail.com>
Date:   Wed Dec 20 13:17:28 2023 +0530

    first file change
=================================

git files lifecycle
git add . or filename 

to view the all files added in stagging area
$ git ls-files
chat-sheet.txt
===================git ls-files more info=============
 git ls-files -a
error: unknown switch `a'
usage: git ls-files [<options>] [<file>...]

    -z                    separate paths with the NUL character
    -t                    identify the file status with tags
    -v                    use lowercase letters for 'assume unchanged' files
    -f                    use lowercase letters for 'fsmonitor clean' files
    -c, --cached          show cached files in the output (default)
    -d, --deleted         show deleted files in the output
    -m, --modified        show modified files in the output
    -o, --others          show other files in the output
    -i, --ignored         show ignored files in the output
    -s, --stage           show staged contents' object name in the output
    -k, --killed          show files on the filesystem that need to be removed
    --directory           show 'other' directories' names only
    --eol                 show line endings of files
    --empty-directory     don't show empty directories
    -u, --unmerged        show unmerged files in the output
    --resolve-undo        show resolve-undo information
    -x, --exclude <pattern>
                          skip files matching pattern
    -X, --exclude-from <file>
                          read exclude patterns from <file>
    --exclude-per-directory <file>
                          read additional per-directory exclude patterns in <file>
    --exclude-standard    add the standard git exclusions
    --full-name           make the output relative to the project top directory
    --recurse-submodules  recurse through submodules
    --error-unmatch       if any <file> is not in the index, treat this as an error
    --with-tree <tree-ish>
                          pretend that paths removed since <tree-ish> are still present
    --abbrev[=<n>]        use <n> digits to display object names
    --debug               show debugging data
    --deduplicate         suppress duplicate entries
========================================================
*** From staging area to revert a file into working directort
 git rm --cached chat-sheet.txt
rm 'chat-sheet.txt'
git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        deleted:    chat-sheet.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        chat-sheet.txt
If you want to add again you can use

git add . (it will move to the staging area
git commit -m "pushing repo first commit"

From git log if you wand to know more info about commit

git cat-file -p 82bc
tree a5484f0b284e5fea6c831f6cc4d4c9dbff0543dd
parent 7b9fe8f6b2ae057d9ad5660c147722fbb5df6c1e
author shivasingam111 <shivasingam111@gmail.com> 1703060062 +0530
committer shivasingam111 <shivasingam111@gmail.com> 1703060062 +0530
pushing repo first commit

In latest git log tree hash code copy fist 4 digits it will show conatin files in tree

 git cat-file -p 5358
100644 blob 1e3c4215f8daa37de589cf4bcff740b95d1a310c    chat-sheet.txt
100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391    test2

=======================Git Branches=========================
Default branch is master/main
multiple branches will be there in one repo
pointer of all branches are located in .git/refs/heads folder
current branch tracks new commits
branch pointers move auto to every new commit



git branch -d brach-name (will delete only merged branch)

if you want to delete the non-merged branch

git branch -D branch-name 

Git branch Create branch:

$ git branch List Branch:

$ git branch --list Delete a Branch:

$ git branch -d Delete a remote Branch:

$ git push origin -delete Rename Branch:

$ git branch -m

Git checkout

Switch between branches in a repository.

Switch to a particular branch:

$ git checkout

Create a new branch and switch to it:

$ git checkout -b Checkout a Remote branch:

$ git checkout

Git stash

Switch branches without committing the current branch. Stash current work:

$ git stash

Saving stashes with a message:

$ git stash save ""

Check the stored stashes:

$ git stash list

Re-apply the changes that you just stashed:

$ git stash apply

Track the stashes and their changes:

$ git stash show

Re-apply the previous commits:

$ git stash pop

Delete a most recent stash from the queue:

$ git stash drop

Delete all the available stashes at once:

$ git stash clear

Stash work on a separate branch:

$ git stash branch

Git cherry pic

Apply the changes introduced by some existing commit:

$ git cherry-pick

8. Merging

Git merge

Merge the branches:

$ git merge

Merge the specified commit to currently active branch:

$ git merge

=============================HEAD===============


The HEAD points out the last commit in the current checkout branch. It is like a pointer to any reference. The HEAD can be understood as the "current branch." When you switch branches with 'checkout,' the HEAD is transferred to the new branch.

git show HEAD

git show commitid


***in GIT jump to specific commit the command is:

git checkout the-commit-id

==========================git remote=============================

git clone https://github.com/ImDwivedi1/Git-Example  


Some commands in which the term origin and master are widely used are as follows:


Git push origin master

Git pull origin master



** Check your Remote


To check the configuration of the remote server, run the git remote command. The git remote command allows accessing the connection between remote and local. If you want to see the original existence of your cloned repository, use the git remote command. It can be used as:



Syntax:


$ git remote  


git remote -v:


Git remote supports a specific option -v to show the URLs that Git has stored as a short name. These short names are used during the reading and write operation. Here, -v stands for verbose. We can use --verbose in place of -v. It is used as:


********Add remote origin to local machine

Syntax:

$ git remote -v  

git remote add <short name><remote URL>

ex: git remote add origin https://github.com/shivscloud/git-professional.git

git push -u origin main

****Git Remove Remote

You can remove a remote connection from a repository. To remove a connection, perform the git remote command with remove or rm option. It can be done as:

Syntax:

$ git remote rm <destination>  

Or

$ git remote remove <destination>  

git remote rename <old name><new name>  

git Show Remote

To see additional information about a particular remote, use the git remote command along with show sub-command. It is used as:

Syntax:

$ git remote show <remote>

*****Git Remote Set:

We can change the remote URL simply by using the git remote set command. Suppose we want to make a unique name for our project to specify it. Git allows us to do so. It is a simple process. To change the remote URL, use the below command:

$ git remote set-url <remote name><newURL>  

** git tag

 git tag <tag name>

git tag show <tagname>  

git tag projectv1.0  

 git push --tags  

git tag --delete <tagname>

git push origin -d <tagname> 

git checkout -b < new branch name> <tag name>  (create a branch with tag)

***Upstream and Downstream

The term upstream and downstream refers to the repository. Generally, upstream is from where you clone the repository, and downstream is any project that integrates your work with other works. However, these terms are not restricted to Git repositories.

There are two different contexts in Git for upstream/downstream, which are remotes and time/history. In the reference of remote upstream/downstream, the downstream repo will be pulled from the upstream repository. Data will flow downstream naturally.

In the reference of time/history, it can be unclear, because upstream in time means downstream in history, and vice-versa. So it is better if we use the parent/child terms in place of upstream/downstream in case of time/history.

**Git set-upstream

git remote -v  

The above command will list the branches on the local and remote repository. To learn more about branches, click here. Now push the changes to remote server and set the particular branch as default remote branch for the local repository. To push the changes and set the remote branch as default, run the below command:

$ git push --set-upstream origin master

***We can also set the default remote branch by using the git branch command. To do so, run the below command:

$ git branch --set-upstream-to origin master  

==================================GIt DIFF===========================

==========git diff===========================

Git Diff

Git diff is a command-line utility. It's a multiuse Git command. When it is executed, it runs a diff function on Git data sources. These data sources can be files, branches, commits, and more. It is used to show changes between commits, commit, and working tree, etc.


1.Scenerio1: Track the changes that have not been staged.(to check changes in diff files)


Scenerio2: Track the changes that have staged but not committed:

git diff --staged  


Scenerio3: Track the changes after committing a file:

git diff HEAD  


Scenario4: Track the changes between two commits:

git log

git diff <commit1-sha> <commit2-sha>

git diff <branch 1> < branch 2>

=============================================








Post a Comment

0 Comments

Ad Code

Responsive Advertisement