***GIT Official chat sheet:https://git-scm.com/docs
===================Git Config===================
1. Git configuration
Get and set configuration variables that control all facets of how Git looks and operates.
GIT Object types:
BLOB
Tree
Commit
Note: Each git commit having backed author name & email commit description (parent-optional)
*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:
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
$ git cat-file -s cae3
200
git cat-file -t cae3
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>
=============================================
0 Comments