Suggested Certification for Git

GitLab Certified Git Associate

Recommended Book 1 for Git

★★★★☆
Check Amazon for current price
View Deal
On Amazon

Recommended Book 2 for Git

★★★★☆
Check Amazon for current price
View Deal
On Amazon

Recommended Book 3 for Git

★★★★☆
Check Amazon for current price
View Deal
On Amazon

Recommended Book 4 for Git

★★★★☆
Check Amazon for current price
View Deal
On Amazon

Recommended Book 5 for Git

★★★★☆
Check Amazon for current price
View Deal
On Amazon

Note: *Check out these useful books! As an Amazon Associate I earn from qualifying purchases.

Interview Questions and Answers

`git cherry-pick` allows you to apply a specific commit from one branch to another branch.

You can view the commit history using `git log`. Use options like `git log --oneline` for a condensed view, `git log --graph` for a graphical view, and `git log --author=` to filter by author.

Git is configured using `git config`. You can set global configuration options with `git config --global ` and repository-specific options with `git config `.

Git hooks are scripts that run automatically before or after certain Git events, such as commit, push, and receive. They can be used to enforce coding standards, run tests, or perform other automated tasks.

To delete a local branch, use `git branch -d ` (only if the branch is fully merged) or `git branch -D ` (to force deletion, even if not merged). To delete a remote branch, use `git push origin --delete `.

A `.gitignore` file specifies intentionally untracked files that Git should ignore. This is useful for excluding build artifacts, temporary files, or sensitive information from being committed.

Typically, you fork the repository, clone your fork, create a branch for your changes, commit your changes, push your branch to your fork, and then create a pull request to the original repository.

`git merge` creates a merge commit to integrate changes. `git rebase` rewrites the commit history by moving your branch onto another branch, creating a cleaner, linear history. Rebase can be more complex and risky if not used carefully.

A detached HEAD state occurs when youre not on a branch. To fix it, create a new branch from the commit youre on (`git checkout -b `) or checkout an existing branch (`git checkout `).

To merge a branch into your current branch, use the command `git merge `. This will combine the changes from the specified branch into your current branch.

A merge conflict occurs when Git cannot automatically merge changes from two different branches. You need to manually edit the conflicting files to resolve the conflict, then stage and commit the changes.

`git stash` allows you to save uncommitted changes temporarily, cleaning up your working directory. You can then restore these changes later using `git stash pop` or `git stash apply`.

There are several ways to undo a commit. `git revert ` creates a new commit that undoes the changes from the specified commit. `git reset --hard ` moves the branch pointer back to the specified commit, discarding all subsequent commits (use with caution!).

`git reset --soft` moves the branch pointer but keeps the changes staged. `git reset --mixed` (the default) moves the branch pointer and unstages the changes. `git reset --hard` moves the branch pointer and discards the changes.

To rename a local branch, use the command `git branch -m `.

Git is a distributed version control system that tracks changes to files over time. Its used for collaboration, managing code versions, and reverting to previous states.

Basic Git commands include `git init` (initialize a repository), `git clone` (copy a repository), `git add` (stage changes), `git commit` (record changes), `git push` (upload changes), `git pull` (download changes), and `git status` (check repository status).

`git fetch` downloads objects and refs from another repository but doesnt integrate them into your working copy. `git pull` downloads objects and refs AND integrates them into your working copy, essentially doing a `git fetch` followed by a `git merge`.

A Git branch is a pointer to a snapshot of your changes. It allows you to work on new features or bug fixes in isolation without affecting the main codebase, making collaboration and parallel development easier.

You can create a new branch using the command `git branch `. To switch to the newly created branch, use `git checkout ` or `git checkout -b ` to create and switch in one command.