1. How do you create a new repository in GitHub?
A GitHub repository is a centralized location to store, manage, and track changes to your project files. It supports collaboration and version control.
- Log in to your GitHub account.
- Click the “+” icon in the top-right corner and select “New repository”.
- Enter a repository name and optional description.
- Choose visibility: Public or Private.
- Click “Create repository”.
2. How do you clone a repository to your local machine?
Cloning downloads a repository from GitHub to your local system, enabling offline development.
git clone https://github.com/username/repository.git
3. How do you create a new branch in Git?
Branches let you isolate development work without affecting the main codebase.
git branch feature-branch
git checkout feature-branch
4. How do you merge a branch into the main branch?
Merging integrates changes from one branch into another, typically from a feature branch into main
.
git checkout main
git merge feature-branch
5. How do you resolve merge conflicts in Git?
Conflicts occur when changes in different branches overlap. Git marks the conflicting sections in affected files.
- Edit the conflicting files manually.
- Mark resolved sections.
- Stage the changes:
git add filename
- Commit the resolution:
git commit
6. How do you push changes to a remote repository?
Pushing sends your local commits to the remote repository on GitHub.
git push origin branch-name
7. How do you pull the latest changes from a remote repository?
Pulling fetches and merges changes from the remote repository into your current branch.
git pull origin branch-name
8. How do you create a pull request in GitHub?
Pull requests propose changes and allow for code review before merging.
- Push your branch to GitHub.
- Navigate to the repository.
- Click “Pull Requests” > “New Pull Request”.
- Select the base and compare branches.
- Review changes and click “Create Pull Request”.
9. How do you revert a commit in Git?
Reverting creates a new commit that undoes the changes of a previous commit without altering
Search
Categories
Recent Posts
Top Git interview Questions for Experienced Developer
Speed-up tips and tricks for Windows 11
Top 15 Linux Commands used by Experienced Developer
Top SQL Interview Examples for Experienced Developer
Internal Working of Java HashMap
Recent Tags