GIT Questions
GIT Questions
6. Git show - It shows the author's name, timestamp, commit message, and difference from the
previous commit.
7. Git diff – takes two input datasets & outputs the changes i.e., differences between 2 files
8. Remote – remote repository origin – default name of remote url
9. Git clone url - downloads the complete project, all branches, commits and logs from the given
remote URL (react repo here) to your local machine.
10. Git pull <remotename> <branchname> - pull changes from remote to local repo
11. Git push <remotename> <branchname> - push changes from local to remot repo
12. Git remote add <remote_name> <remoteurl> - link your local repo with remote repo
13. Branch – complete copy of ur complete project
14. Create branch – git branch <name>
15. List all branches – git branch -a
16. Creating new branch & switches to it:
22. Rebase - if you are re-basing feature branch with master, the command will remove the original
commits on feature, bring all the commits from master to feature and add the original commits
on top of it - changes the commit hashes and re-writes the history
23. Merge vs rebase
24. git commit --amend command is used to fix your previous commit where you do not want to
add a new commit
25. Git Checkout is used to switch. You can switch between branches, commits, and files.
26. Git reset - If you have staged your changes and forgot to add something, you can reset the file,
so the file is moved from staging to working area where you can make the required changes.
27. Git revert - git revert is another command to undo changes from an old commit, similar to reset.
However, git revert inverses the changes from that old commit and creates a new revert
commit, instead of deleting the old commit. – prevents git from losing history
32. Git stash temporarily saves the changes you have made in your working directory
git stash pop: Gets your changes from stashed list and applies in the working area
33. Tag allows you to capture a reference point in your project history, such as release versions
34. An annotated tag contains additional information such as name, message, and email of the
person who created the tag
35. git tag: Adds a tag to a commit
36. git tag -a -m: Adds an annotated tag with a message
37. git push tag name: Pushes tag to the remote repo
38. Git submodule will allow you to add a vendor library to your project and get their future updates
instantly.
To add a Git submodule use:
Syntax: git submodule add <URL of vendor library>
39. git blame - to find the author of lines 5 to 7 in the file Readme.md
Example: git blame –L 5,7 Readme.md
40. Whenever you find buggy behavior or an unknown error, you need to find the commit that
introduced it.
In that case, you may not know the exact file name. This is where Git Bisect comes into the
picture.
Git Bisect will:
Perform a binary search in the commits
Allow us to check it manually
Allow us to declare its status as good or bad
When this process is repeated, the commit which introduced the bug will be found.
41. Git Hooks are shell scripts that get triggered when we perform a specific action in Git
42. git log will track every commit that you make and record it as a snapshot at a particular time,
whereas git reflog will keep track of commits that are made as well as the commits that are
discarded.
43. The git reflog command will list down the logs whenever the HEAD changes like the branch was
created, cloned, checked-out, renamed, or any commits made on the branch.
44.