Debug School

Mohammed Zaid
Mohammed Zaid

Posted on

Git Assignment # 2

  1. What is Git and why is it important in software development?

GIT is a version control system. It records the changes made to our code in its repository. We can see the history of the changes made, and can see who has made changes, when and why the changes were made. With GIT we can easily revert back to previous version of code, if the new version does not work properly.

  1. Explain the difference between Git and GitHub.

GIT is a version control system that records the changes made to our code in its repository whereas GitHub serves as a location for uploading copies of a Git repository

  1. How does Git handle version control?

Git records the changes made in our code and stores it in repository, so that a specific version can be called later if needed.

  1. Discuss the three main states of a Git file: committed, modified, and staged.
  • committed: This state indicates that the file is safely stored in the local repository.
  • modified: When we make any change to an already committed file, the state of the file changes from committed to modified.
  • staged: it means that the file is now ready to be added to the local git repository.
  1. How can you create a new Git repository and clone it to your local machine?

To create a new git repository, we use the git init command.
To clone the repository to local machine, we use git clone command.

  1. What is the difference between a Git branch and a tag?

The difference between tag and branch is that a branch always points to the top of a development line and will change when a new commit is pushed whereas a tag will not change. Tags always point to the same object and they do not change.

  1. How do you merge changes from one branch to another in Git?

To merge changes from on branch to another, we use "git merge" command. Before using this command we use "git checkout" to checkout the current branch.

  1. Explain the purpose of the .gitignore file in Git.

The gitignore makes sure that that certain files that we do not want to be tracked by Git remain untracked.

  1. Discuss the Git workflow for a team of developers.

Developers first clone the central repository.
In their own local copies of the project, they edit files and commit changes. These new commits are stored on local repository.
To publish changes to the official project, they push their local main branch to the central repository.
Other developer can pull the latest file from the repository.

  1. How can you resolve a Git conflict when merging branches?
  • To resolve a merge conflict, edit the conflicted file in the editor(like VS Code).
  • Once the file has been edited use git add merge.txt to stage the new merged content.
  • To finalize the merge create a new commit by executing "git commit" command.
  1. What is the significance of the Git HEAD pointer?

The HEAD pointer always points to the top of the current branch in the repository. In Git, only one branch can be checked out at a time and this branch is called the "HEAD" branch.

  1. Discuss the difference between a Git pull and a Git fetch.
  • The Git pull command is used to fetch the contents from remote repository and merge with another repository or local branch.
  • The git fetch command is used to fetch ,or to download the content from a remote repository.
  1. Explain the difference between Git rebasing and Git merging.

Git merge is a command that is used to merge Git branches while the logs of commits on branches remain intact whereas Git rebase is used to integrate changes from one branch to another, and the logs are modified once the action is complete.

  1. How can you recover a deleted branch in Git?
  • Use the command "git reflog" and find the SHA1 for the commit at the tip of your deleted branch.
  • Now, use "git checkout [sha1]", where [sha1] is sha of deleted branch.
  • Once we at that commit, use "git checkout -b [branchname]" to recreate the branch.

Top comments (0)