GIT Knowledge Area

 1. What is the command to check the git version?

git --version

2. what is the command to create a new git repository?

git init

3. What is the command used to check the changed files in our local branch ?

git status

4. What do staged files mean?


Files that are ready to commit

5. What is the command to add a modified file into git?


git add <filename>.extension

6. What is the command to add all the changed files into git?

  • git add .
  • git add --all

7. What does commit mean?


Adding changes to the local branch

8. What is the command to add commits?

git commit -m "commit message"

9. what does git status --short say?


It is used to check the status in our repository in a compact way

10. What do??, M, D, A refer in git status --short command?

  • ?? - untracked files
  • M -  modified files
  • D - deleted files
  • A - Files added to stage

11. How to check the history of the commits?

git log

12. How to get a detailed description of what each command does?

  • git <command> -help
  • git help --all

13. How to clone the repository into your local?

git clone <repo name>.git

14. What does a git fetch do?


Download objects and references from the remote repo

15. What does git merge refer to?


join two or more histories together

16. What does git pull do?


fetch from another repository and integrate changes with our local branch

17. What does git rebase do?


Re-apply commit on top of another commits

18. What does git push refer to?


Update reference of remote repo with local branch changes

19. What does git revert do?


revert some existing commits

20. What does git stash do?


Temporary keep the changes away

21. What is a branch in git?

A separate version of the main repo

22. How to create a new branch in git?

git branch <branch name>

23. How do you move into the specific branch?

git checkout <branch name>

24. What does the git add command use for?


No changes added to the commit

25. What does git commit -a refer to?


No changes added to the commit

26. What does --all do?


it will stage all changed(new , modified, deleted) files names 

27. What does git checkout -b <branch name> do?

It will create a new branch and checkout into that branch

28. What is the command to delete a branch?

git branch -d <branch name>

29. what is the command to merge the branch changes?

git merge <branch name>

30. What does cherry-pick refer to?

When we want to merge only specific commits to other branch
git cherry-pick <commit id>

31. What is the purpose of .gitignore command?


it has the file names which we need to ignore

32. How to create .gitignore file in the root directory?

touch .gitignore

33. How to add ignore all files with extension log?


*.log

34. How do you ignore all files in a specific folder?


temp/

35. What is SSH?

secure shell network protocol

36. What does SSH do?

It provides SSH key-value pairs to authenticate and encrypted way to connect in a secured way in an unsecured network

37. What does git log --oneline

show one line per commit

38. What does git revert do?


it does only specific commit
not all the subsequent commit
It will create a new commit that inverses the changes specified

39. what does git reset do?


it will move to the previous stage where we were before the commit

40. What is the code for git reset?


git reset <commit id>

41 what does amend do?

  • modify the latest commit
  • If we want to change the commit message of the previous commit we can add the command below
  • git conmit --amend  - m "commit message"

How to initialize the git repository?

using the git init command

git init

The difference between git pull and git fetch

git pull: is used to get and download content from a remote repository and immediately update the local repository to match that content

git fetch: really only downloads new data from a remote repository — but it doesn’t integrate any of this new data into your working files. Fetch is great for getting a fresh view of all the things that happened in a remote repository. It gives what everybody else is doing with the repository at that time.

What is the purpose of a .gitignore file?

it specifies the files that need to be ignored which means the files do not need to commit to remote repo.

How to create a branch in git using the git command?

Use git branch branch_name

How to checkout to a branch?

git checkout branch_name

What is a git commit?

git commit record changes to the repository. It includes a snapshot of changes, author, timestamp, unique identifier

 What is git rebase?

  1. We are working in our branch.
  2. We have already multiple commits
  3. We understand that the master branch also updates with new commits
  4. We need to integrate those commits with our branch
  5. We run the below command
//feature is our branch
//main is the master branch
git checkout feature
git rebase main

6. What happens here is this first take our branch into initial stage (The soon after create branch)

7. It will first integrate master branch commits separately.

8. On top of that it will integrate out commits separately.

9. Here disadvantage is history re write

10. Advantage is we can see each commit separately

8. What is git merge? 

  1. We are working in our branch.
  2. We have already multiple commits
  3. We understand that master branch also update with new commits
  4. We need to integrate those commits with our branch
  5. We run below command
//feature is our branch
//main is the master branch
git merge feature main

6. It will update our branch with main branch commits. 

7. It will show as one single merge commits even there are multiple commits

8. That single merge commit is added on top of our commits

9. Disadvantage here is we cannot see the history since it is a single merge commit

https://www.atlassian.com/git/tutorials/merging-vs-rebasing

9. How git stash works?

  1. takes your uncommitted changes (both staged and unstaged), saves them away for later use, and then reverts them from your working copy
  2. When you are working on your branch and you realized that master branch is changed with new content
  3. You do the git stash (Save your work for later use)
  4. Then git pull origin master
  5. Then git unstash (Add your changes on top of master branch changes)

10. Git commands from checkout to push

git clone reponame
git fetch ( check the latest brnaches, changes , etc…)
git checkout branchname
git pull origin master
//// Do the code changes on your branch
git add .
git add specificfilaname.java/txt/...
git commit -m "commit message"
git push
// create pull request from bit bucket

11. What is git pull origin master?

Update local branch with the latest updates from the master branch

12. What is conflict?

When two branches have done changes to the same line in a file.

//checkout to the branch

git status

// indellij idea
VCS-> Resolve Conflicts
Dialog appears
Select file
Click on merger
It will open side by side window
Master branch and local branch changes
Check line by line in conflicted areas and manuall add or remove them
After everything is done
git commit
  • On case-insensitive file systems (e.g., Windows and macOS), Git may treat Verify_etc.spec.ts and
  • verify_etc.spec.ts as the same file.
  • The explicit git mv command forces Git to track the rename operation, including changes in case.

  • Solution: Rename with Temporary Name

    1. Rename to a Temporary Name:


      git mv Verify_etc.spec.ts temp_file.spec.ts

      This explicitly tells Git to rename the file.

    2. Rename to the Desired Name:


      git mv temp_file.spec.ts verify_etc.spec.ts
    3. Commit the Changes:


      git commit -m "Fix filename case to verify_etc.spec.ts"
    4. Push the Changes:


      git push
  • How to resolve git conflicts?

    1.Open project from intellJ idea

    2.git pull origin master

    3. VCS - > Git -> REsolve conflicts

    4.Check and add codes

    5.Left - master  right - local branch

    6.once done   git status

    7.git commit

    8.git push or git push -f






    Comments