Git Flashcards
What is Git?
GIT is a distributed version control system and source code management (SCM) system with an emphasis to handle small and large projects with speed and efficiency.
What is Repository?
A repository contains a directory named .git, where git keeps all of its metadata for the repository. The content of the .git directory are private to git.
What is the command to write a commit message in Git?
Answer:
Use:
git commit -a
-a on the command line instructs git to commit the new content of all tracked files that have been modified. You can use
git add <file>
or</file>
git add -A
before git commit -a if new files need to be committed for the first time.
What is the difference between git pull and git fetch?
In the simplest terms, git pull does a git fetch followed by a git merge.
When you use pull, Git tries to automatically do your work for you. It is context sensitive, so Git will merge any pulled commits into the branch you are currently working in. pull automatically merges the commits without letting you review them first. If you don’t closely manage your branches, you may run into frequent conflicts.
When you fetch, Git gathers any commits from the target branch that do not exist in your current branch and stores them in your local repository. However, it does not merge them with your current branch. This is particularly useful if you need to keep your repository up to date, but are working on something that might break if you update your files. To integrate the commits into your master branch, you use merge.
What’s the difference between a pull request and a branch?
A branch is just a separate version of the code.
A pull request is when someone take the repository, makes their own branch, does some changes, then tries to merge that branch in (put their changes in the other person’s code repository).
What is Git fork? What is difference between fork, branch and clone?
A fork is a remote, server-side copy of a repository, distinct from the original. A fork isn’t a Git concept really, it’s more a political/social idea.
A clone is not a fork; a clone is a local copy of some remote repository. When you clone, you are actually copying the entire source repository, including all the history and branches.
A branch is a mechanism to handle the changes within a single repository in order to eventually merge them with the rest of code. A branch is something that is within a repository. Conceptually, it represents a thread of development.
You need to update your local repos. What git commands will you use?
It’s a two steps process. First you fetch the changes from a remote named origin:
git fetch origin
Then you merge a branch master to local:
git merge origin/master
Or simply:
git pull origin master
If origin is a default remote and ‘master’ is default branch, you can drop it eg. git pull.
What is “Staging Area” or “Index” in GIT?
Before completing the commits, it can be formatted and reviewed in an intermediate area known as ‘Staging Area’ or ‘Index’.
What is the function of git clone?
The git clone command creates a copy of an existing Git repository. To get the copy of a central repository, ‘cloning’ is the most common way used by programmers.
What is the function of git remote?
Git Remote: Git remote command helps you to create, delete, and view connections between remote and local. To view the original file of the copied repository, use the git remote command as
Command used: $ git remote
How do you create a Git repository?
To develop a repository in git, use the command “git init” on the created project directory. If the directory of the project is not created then you need to create a new directory and then run the command “git init”.
How git status is different from git diff?
Git Status: Git Status Shows the difference between the working directory and index.
Git Diff: Git Diff Shows the changes between commits and the working directory.
What is a ‘conflict’ in git?
A ‘conflict’ arises when the commit that has to be merged has some change in one place, and the current commit also has a change at the same place. Git will not be able to predict which change should take precedence.
How can conflict in git resolved?
To resolve the conflict in git, edit the files to fix the conflicting changes and then add the resolved files by running “git add” after that to commit the repaired merge, run “git commit”. Git remembers that you are in the middle of a merger, so it sets the parents of the commit correctly.
What is the syntax for “Rebasing” in Git?
The syntax used for rebase is “git rebase [new-commit] “