Git Architecture Diagram
There are following git commands.
- git config
- git init
- git clone
- git add
- git commit
- git diff
- git reset
- git status
- git rm
- git log
- git show
- git tag
- git branch
- git checkout
- git merge
- git remote
- git push
- git pull
- git stash
Git
Commands
|
Description
|
git init | git init : To Initialize a git repo. git init creates an empty Git repository or re- initializes an existing one. Its creates a .git directory with sub directories and template files |
git status | git status : To check the current status of
your local repository. Its will show all uncommite modified files which are ready to be added to the local repository. We should use this commed before to commit code. |
git add | This command adds a change from
the working directory to the staging area. git add <directoryname> :- To add new directory or folder to the staging area. git add <filename> :- Add a file to the staging area. git add -A :- Add all new changed files to the staging area. git add * :- Add all the changes in one or more file to the staging area. |
git commit | git commit
-m "<commit message>" : The
"commit" command is used to save your
changes in the staging area (from staging area ) to local
repository git commit -a :- commit a snapshot of all the changes in the working directory at once. Note :- git command "git commit" takes all changes in the Staging Area, wraps them together and puts them in to Local Repository |
git pull | git pull <branch-name> : pull code from a branch. git pull origin <branch-name> : pull code from origin master. |
git push | git push <remote>: This command is use to push the committed changes of master branch to your remote repository git push <remote> –force : git push <variable_name> <branch_name> : This command is used to push the branch commits to your remote repository.. where variable_name is like origin etc. |
git branch | git branch : This command is used to lists all the branches in the current repository. git branch <branch-name> : To create a new branch git branch -d <branch-name> : This command is used to delete the branch. where -d stands for --delete, it will delete the local branch only, if it is already pushed and merged with your remote branches. git branch -D <branch_name> : This command is used to delete branch forcefuly. where -D stands for --delete --force, it will delete the branch forcefuly, regardless of its push and merge status, so be careful using this one! |
git diff | git diff: This command use to check all the file differences(changes) which are not staged or commited yet. git diff –staged : This command use to check the differences between the files in the staging(commeted but not push to remote) area and the latest version present. git diff <first-branch-name> <second-branch-name > : This command used to shows the differences between the two branches files. |
git reset | git reset <file-name> : This command used to unstages the file changes, but it preserves the file contents. git reset <commit-version> : This command is used to undoes all the commits after the specified commit and preserves the changes locally. git reset –hard <commit-version> : This command is used to discards all history and goes back to the specified commit. |
git rm | git rm <file-name>: This command is used to deletes the file from local working directory and stages area. |
git log | git log : This is used to list the all version history for the current branch. git log –follow <file-name> : This command is used to lists version history of a file, including the renaming of files also. |
git show | git show <commit-version> : This command is used to shows the metadata and content changes of the specified commit-version. |
git tag | git tag <commitID> : This is used to give(provide) the tags to the specified commit. |
git checkout | git checkout <branch_name> : This is used to switch from one branch to another. git checkout -b <branch name> : This command is used to creates a new branch and also switches to it |
git merge | git merge <branch_name> : This command is used to merges the specified branch history into the current branch. |
git remote | git remote add <variable_name> <Remote Server Url> : This is used to connect local repository to the remote server. Where variable_name like origin etc. |
git stash | git stash : This command is used to temporarily stores all the modified or changes into tracked files. git stash save : This is same as git stash. git stash pop : This command is used to restores the most recently stashed changes into files. git stash list : This command is used to lists all stashed change sets. git stash drop : This command is used to discards the most recently stashed change set. |
Note : - The above command is usefull while using git bash as command-line tools.
Q- How to Delete a remote GIT branch?
git push <remote_name> --delete <branch_name>
Q- What is the difference between git clone and git pull?
Q- What is the difference between Head vs Master vs Origin Master in git?
Answer :
- HEAD : HEAD is a pointer. which always point to latest (most recent) commit of the branch. while we modify and commit in branch. header is updated with the latest commit branch. the header of the branch is stored in the .git/refs/head directory
- Master : master is the default branch created when you initialized a git repository. we can delete branch but can not delete head.
- Origin Master :
Q- What is difference between pull Vs fetch Vs merge in git?
Answer:
- Pull : git pull does a git fetch followed by a git merge. (fetch + merge)
- Fetch : fetch the data without merge. (fetch never changes any of our own local branches under refs/heads , and is safe to do without changing your working copy).
- Merge : merge is use to changes from multiple branches into one.
Answer :
When we push the code to reopo and ask to devops team to pull your code. its call pull request.
Note :-
- git add :- Add all new and changed files to the staging area.
- git command "git commit" takes all changes in the Staging Area, wraps them together and puts them in to Local Repository
Q- how to get latest code from remote branch.
Git command: git pull origin/master
visit: Git pull from master into the development branch
Git command: git pull origin/master
visit: Git pull from master into the development branch
No comments:
Post a Comment