GIT Flashcards
What is a version control system (VCS)?
A VCS
- keeps track of the contributions of the developers working as a team on the projects.
- maintains the history of code changes done and with project evolution, it gives an upper hand to the developers to introduce new code, fixes bugs, and run tests with confidence that their previously working copy could be restored at any moment in case things go wrong.
What is a git repository?
A repository is a file structure where git stores all the project-based files. Git can either stores the files on the local or the remote repository.
Steps to install git
- git - will tell you whether it is installed already
- download from the web
What does git clone do?
The command creates a copy (or clone) of an existing git repository. Generally, it is used to get a copy of the remote repository to the local repository.
How can you see a history of the git commits ?
git log
**git log -2 **(show just the last two commits)
How do you get rid of ‘unstaged changes’ ?
in other words, the file is being tracked by git, you have made uncommited/unstaged changes to it which you want to discard
git checkout – filename
or git checkout – . (for all the files)
or git restore filename
git checkout also used to switch branches.
How do you unstage a change ?
***git restore –staged <file>***</file>
what if you dont want to include certain files in your git repo ?
use .gitignore file
- should check in the .gitignore file so it stays with the repo
How do you delete a file ?
the delete is the same as a change. a new commit is made to reflect the deletion.
How do you create an issue ?
you can create an issue in Git by following these steps:
On GitHub.com, navigate to the main page of the repository.
Under your repository name, click Issues.
Click New issue.
What is a pull request ?
A pull request is a feature in Git that allows developers to propose changes to a codebase hosted on GitHub. It is essentially a request to merge one branch into another.
What is fork ?
A fork is a Git feature that allows you to create a copy of an existing repository. Forking a repository creates a new repository in your account that is identical to the original repository. You can then make changes to the forked repository without affecting the original repository.
What is rebase ?
A rebase is a Git command that allows you to modify the history of a branch. It works by moving the entire branch to begin on the tip of another branch. i.e. move the base of the branch to begin at the tip of another branch
What does the command git config do?
The git config command is a convenient way to set configuration options for defining the behavior of the repository, user information and preferences, git installation-based configurations, and many such things.
For example:
To set up your name and email address before using git commands, we can run the below commands:
- git config –global
user.name
“«your_name»” - git config –global user.email “«your_email»”
Can you explain head in terms of git and also tell the number of heads that can be present in a repository?
- A head is nothing but a reference to the last commit object of a branch.
- For every repository, there will always be a default head referred to as “master” or now “main” (as per GitHub) but there is no restriction to the count of heads available. In other words, it can have any number of heads.
Usages: - To go or checkout to 1 commit before the latest commit, we use git checkout HEAD~1
- To uncommit the last 3 commits without losing the changes, we first run git reset HEAD~3. Then we can see the changes made in the last 3 commits and then update it manually and commit it finally.
- In order to uncommit the last 3 commits and also remove the changes, we can run the command: git reset –hard HEAD~3. This command will completely remove all the changes.
- To look into the changes made in the last 3 commits, we can run git diff HEAD~3
- To make a new commit by reverting the last 3 commits, we can run the command: git revert –no-commit HEAD~3…HEAD
What is a conflict?
- Git usually handles feature merges automatically but sometimes while working in a team environment, there might be cases of conflicts such as:
- When two separate branches have changes to the same line in a file
- A file is deleted in one branch but has been modified in the other.
- These conflicts have to be solved manually after discussion with the team as git will not be able to predict what and whose changes have to be given precedence
What is the functionality of git ls-tree?
This command returns a tree object representation of the current repository along with the mode and the name of each item and the SHA-1 value of the blob.
What does git status command do?
git status command is used for showing the difference between the working directory and the index which is helpful for understanding git in-depth and also keep track of the tracked and non-tracked changes.
Define “Index”.
Before making commits to the changes done, the developer is given provision to format and review the files and make innovations to them. All these are done in the common area which is known as ‘Index’ or ‘Staging Area’.
What does git add command do?
- This command adds files and changes to the index of the existing directory.
- You can add all changes at once using **git add . **command.
- You can add files one by one specifically using ***git add <filename>*** command.</filename>
- You can add contents of a particular folder by using ***git add /<foldername>/ ***command</foldername>
these files go to Staging - they still need to be Commited
Why is it considered to be easy to work on Git?
With the help of git, developers have gained many advantages in terms of performing the development process faster and in a more efficient manner. Some of the main features of git which has made it easier to work are:
- Branching Capabilities:
- Due to its sophisticated branching capabilities, developers can easily work on multiple branches for the different features of the project.
- It also has an easier merge option along with an efficient work-flow feature diagram for tracking it.
- Distributed manner of development:
- Git is a distributed system and due to this nature, it became easier to trace and locate data if it’s lost from the main server.
- In this system, the developer gets a repository file that is present on the server. Along with this file, a copy of this is also stored in the developer’s system which is called a local repository.
- Due to this, the scalability of the project gets drastically improved.
- Pull requests feature:
- This feature helps in easier interaction amongst the developers of a team to coordinate merge-operations.
- It keeps a proper track of the changes done by developers to the code.
- Effective release cycle:
- Due to the presence of a wide variety of features, git helps to increase the speed of the release cycle and helps to improve the project workflow in an efficient manner.
How will you create a git repository?
- Have git installed in your system.
- Then in order to create a git repository, create a folder for the project and then run git init.
- Doing this will create a .git file in the project folder which indicates that the repository has been created.
Tell me something about git stash?
Git stash can be used in cases where we need to switch in between branches and at the same time not wanting to lose edits in the current branch. Running the git stash command basically pushes the current working directory state and index to the stack for future use and thereby providing a clean working directory for other tasks