Journal logo

Git Top Interview Questions by Top companies (Part 6) 2023

Essential Git Interview Questions (Part 6) 2023

By ManisekaranPublished about a year ago 4 min read
Like
Git Top Interview Questions by Top companies (Part 6) 2023
Photo by Roman Synkevych 🇺🇦 on Unsplash

Can you explain the different Git access levels on GitHub?

GitHub allows you to set different access levels for different users on a repository. There are three main access levels on GitHub:

Read access: Allows users to view the repository and its contents, but not make any changes. This is the default access level for users who are not collaborators on a repository.

Write access: Allows users to make changes to the repository, such as pushing commits and creating pull requests. This is the access level for collaborators on a repository.

Admin access: Allows users to make changes to the repository, such as modifying the repository settings and managing collaborators. This access level is typically reserved for the repository owner or a designated administrator.

It's worth noting that when you add a user as a collaborator to your repository, you can choose between these 3 access levels.

In addition, GitHub also provides the ability to give access to specific branches, or specific file paths within a repository, this is done through branch and file-level permissions. This feature allows you to give specific permissions to people who don't have write access to the entire repository.

It's important to keep in mind that access levels and permissions should be set and managed carefully, to ensure that only authorized users can access and make changes to the repository.

How do you use Git hooks to automate tasks?

Git hooks are scripts that run automatically at certain points in the Git workflow, such as when a commit is made or when changes are pushed to a remote repository. They can be used to automate tasks and enforce certain policies in your development workflow. Here's a general process for how to use Git hooks to automate tasks:

Create a new script:

Create a new script in the "hooks" directory of your Git repository. The name of the script should match the name of the Git hook that you want to use. For example, to run a script when a commit is made, you would name the script "pre-commit".

Define the task: Define the task that you want to automate in the script. For example, you might want to run a linter to check the code for style errors, or run tests to ensure that the code is working correctly.

Make the script executable: Use the command "chmod +x [script name]" to make the script executable.

Test the script: Test the script by running it manually to ensure that it works as expected.

Use the hook: Once you've set up and tested the script, Git will automatically run it at the appropriate point in the workflow. For example, if you've set up a "pre-commit" hook, the script will run automatically before each commit is made.

It's worth noting that git hooks are specific to each repository and they only run locally, this means that every developer in the team must set them up individually.

Git hooks are powerful tools that can be used to automate many tasks, such as code quality checks, testing, and deployment. However, they can also be used to enforce policies, such as ensuring that all commits have a specific format, or that all code changes are reviewed before they are committed.

Can you explain Git stash and its use case?

Git stash is a command that allows you to temporarily save changes that you have made to your working directory, but that you are not ready to commit yet. Here's an example of how you might use Git stash:

Let's say you're working on a feature branch, and you've made some changes to your code that you're not ready to commit yet. But, you need to switch to a different branch to work on a different task.

Instead of committing your changes and creating a new branch, or discarding your changes, you can use the command "git stash" to save your changes temporarily.

git stash

This command will save your changes in a new stash, and it will restore your working directory to the state of the last commit. Now, you can switch to a different branch to work on your other task.

git checkout [branch name]

Once you're done with your other task, you can switch back to your original branch, and use the command "git stash apply" to apply the saved changes to your working directory.

git stash apply

If you have multiple stashes, you can use the command "git stash list" to view the list of stashes, and "git stash apply [stash name]" to apply a specific stash.

Git stash is a useful feature when you need to switch to work on another task but don't want to commit the changes yet. It allows you to save your work temporarily, switch branches.

product reviewworkflowlisthow tofeaturecareerbusiness warsbusinessbook reviewadvice
Like

About the Creator

Manisekaran

Reader insights

Be the first to share your insights about this piece.

How does it work?

Add your insights

Comments

There are no comments for this story

Be the first to respond and start the conversation.

Sign in to comment

    Find us on social media

    Miscellaneous links

    • Explore
    • Contact
    • Privacy Policy
    • Terms of Use
    • Support

    © 2024 Creatd, Inc. All Rights Reserved.