Git Flashcards

Category sponsor

Git is a distributed version control system created by Linus Torvalds. It is a tool designed for speed, data integrity, and support for distributed, non-linear workflows. Git is characterized by flexibility and efficiency, allowing for effective management of both small and large software projects. This system offers advanced branching and merging functions, providing developers with tools for efficient collaboration, change tracking, and source code management. Git also supports offline work and quick switching between project versions, maintaining reliability and allowing easy recovery of change history.

Our flashcard app includes carefully selected Git interview questions with comprehensive answers that will effectively prepare you for any interview requiring Git knowledge. IT Flashcards is not just a tool for job seekers - it's a great way to reinforce and test your knowledge, regardless of your current career plans. Regular use of the app will help you stay up-to-date with the latest Git trends and keep your skills at a high level.

Sample Git flashcards from our app

Download our app from the App Store or Google Play to get more free flashcards or subscribe for access to all flashcards.

What is a 'branch' in Git and how can it be used in the software development process?

A branch, also referred to as a branch in Git, is an independent line of development of a project. It is created when we want to work on new features or bug fixes, without interfering with the main development line (master branch). Branching allows for multiple versions of a project to be run concurrently, which is efficient if multiple developers are working on one project.

The primary use of branches in the software development process is the sequence: creating a new branch, adding changes, committing changes, and then merging those changes with the main branch.

The following example shows the basic operations that can be performed on branches.
# Creating a new branch
git branch new_feature

# Switching between branches
git checkout new_feature

# Adding changes to the branch
# (...) make some changes to files
git add .
git commit -m "New functionality added"

# Go back to master and merge changes from new_feature branch
git checkout master
git merge new_feature

# Delete branch after finishing work
git branch -d new_feature

Thanks to branches in Git, we have the ability to independently work on different parts of the project, which we can then merge at any time.

Describe the difference between the git merge and git rebase commands.

The command git merge is used to combine two or more branches in a project. When you execute git merge, Git creates a new commit that includes changes from both branches. The advantage of git merge is that the history of the project is preserved in its original state. It creates a chronological path of events, which makes it easier to understand what has happened.

On the other hand, git rebase is used to move or "apply" a series of commits to a new base. This is used when you want to maintain a linear historical chart of the project. When you perform git rebase, Git 'pastes' your changes on top of the chosen branch. We can say that git rebase in a way 'cleans up' the history of commits, which can lead to loss of context if a merge/conflict is misunderstood and poorly resolved.

Basically, git merge is used to combine branches and preserve the historical path of the project, while git rebase allows to maintain a clean, linear project chart, but at the expense of losing context. Both methods have their pros and cons, the choice largely depends on the specific situation.

What is a 'detached HEAD' and how can one arrive at it when working with Git?

"Detached HEAD" is a state in which HEAD in Git is not attached to any specific branch. This can be compared to a situation in which our changes are not being saved on any specific branch.

There are several ways to get a "detached HEAD". This most commonly occurs during a checkout to another commit, for example:
git checkout <commit_id>

However, we can also achieve this state during operations like rebase or cherry-pick that did not succeed.

Git refers to this state with the message:
Note: checking out 'commit_id'.
You are in 'detached HEAD' state.

"Detached HEAD" is not a dangerous state, it is a natural part of working with Git. It is important, however, to save our changes that we have made while in the "detached HEAD" state before switching to another commit or branch. We can do this by creating a new branch, the source of which will be our "detached HEAD". We will do this with the command:
git branch new_branch_name

How can you move recent commits from one branch to another?

To transfer the last commits from one branch to another, you can use the `git cherry-pick` command. In the context of GIT, cherry picking means selecting an arbitrary commit from one branch and applying it to another.

The first step is to switch to the branch from which we want to transfer the commits (let's call it branchA):
git checkout branchA

Then, we need to identify the hash of the commits we want to transfer. We can do this using the `git log` command, which will display a list of commits for this branch. The commit hash is a long string of characters at the beginning of each commit entry.

Next, we switch to the branch to which we want to transfer the commits (let's call it branchB):
git checkout branchB

Finally, we use the `git cherry-pick` command along with the commit hash we want to transfer:
git cherry-pick commit-hash

If we want to transfer several commits, we can provide their hashes one after another, separated by a space.

Download IT Flashcards App Now

Expand your Git knowledge with our flashcards.
From basic programming principles to mastering advanced technologies, IT Flashcards is your passport to IT excellence.
Download now and unlock your potential in today's competitive tech landscape.