AZ-400 Exam QuestionsBrowse all questions from this exam

AZ-400 Exam - Question 401


DRAG DROP -

You manage the Git repository for a large enterprise application.

During the development of the application, you use a file named Config.json.

You need to prevent Config.json from being committed to the source control whenever changes to the application are committed.

Which three actions should you perform in sequence? To answer, move the appropriate actions from the list of actions to the answer area and arrange them in the correct order.

Select and Place:

Exam AZ-400 Question 401
Show Answer
Correct Answer:
Exam AZ-400 Question 401

Step 1: Delete and recreate the repository.

Step 2: Add Config.json to the .gitignore file

Each line in the .gitignore excludes a file or set of files that match a pattern.

Example:

# ignore a single file

Config.json -

Step 3: Run the git add .gitignore command

At the initial commit we want basically move from Untracked to Staged, for staging we have to indicate which file we want to move or specify a pattern, as example:

Reference:

http://hermit.no/how-to-find-the-best-gitignore-for-visual-studio-and-azure-devops/ https://geohernandez.net/how-to-add-an-existing-repository-into-azure-devops-repo-with-git/

Discussion

22 comments
Sign in to comment
Sylph
Apr 4, 2021

I think it should be: Add Config.json to the .gitignore file. Run the git add .gitignore command. Run the git commit command.

pexonconsulting
Apr 8, 2021

same here

Kinon4
May 18, 2021

Agree on Sylph's answer

Dalias
Jun 29, 2021

Got this in 30 June 2021 exam. Scored 800+ followed this answer

rfox321
Sep 25, 2021

King! Thank you!

rfox321
Sep 25, 2021

King! Thank you!

[Removed]
Dec 1, 2021

if you dont trust this answer test it and verify for yourself.

Optimist_Indian
Feb 11, 2022

Got this question in Feb-2022 exam (scored 910+). Followed this answer.

FunkyB
Jun 5, 2022

Thanks for sharing.

rdemontis
Mar 25, 2022

you are right

FunkyB
Jun 5, 2022

Thanks for sharing.

adsdadasdad
Aug 17, 2022

DUDE .gitignore is a file, You create the file first then add your file paths into it and once you run the commit git will not commit the files specified in your .gitignore file. PLEASE dont fall for this one and try it yourself.

ravikrg
Oct 10, 2022

1. Adding config.json file to .gitignore file -> Assuming the .gitignore file already exists in the files. But not added to the git yet. 2. `git add .gitignore` -> Adding the .gitignore file to the git, staging it 3. `git commit` commiting the file to the local branch. Answer by sylph makes sense.

ravikrg
Oct 10, 2022

1. Adding config.json file to .gitignore file -> Assuming the .gitignore file already exists in the files. But not added to the git yet. 2. `git add .gitignore` -> Adding the .gitignore file to the git, staging it 3. `git commit` commiting the file to the local branch. Answer by sylph makes sense.

mjansen
Apr 16, 2025

Agreed, Changes to files (in this case .gitignore) should be staged, so git add .gitignore, and then committed.

LeeVee
Apr 5, 2021

Should be 1. Run git add .gitignore 2. Add config.json to the .gitignore 3. Run git commit

lyggwtwtczxnhznebw
Jun 7, 2021

Agreed. The .gitgnore file will not be created by default, so you need to add it manually

zioalex
Jun 14, 2021

This is wrong. If you add the file before modifying it you need to re-add later. The correct sequence is: 1. Add config.json to the .gitignore 2. Run git add .gitignore 3. Run git commit

lyggwtwtczxnhznebw
Jun 18, 2021

This is wrong. git add .gitignore creates the gitignore file. There is no gitignore before running that command, so you cannot add anything to it

celciuz
Aug 18, 2021

"git add .gitignore" does not auto create the .gitignore file. You will need to manually create the .gitignore file in your project root then run "git add .gitignore" to add it as a newly added git file to be tracked and then to be committed by using git commit

lyggwtwtczxnhznebw
Jun 21, 2021

I misunderstood. This is the correct answer. Disregard comment below

celciuz
Aug 18, 2021

"git add .gitignore" does not auto create the .gitignore file. You will need to manually create the .gitignore file in your project root then run "git add .gitignore" to add it as a newly added git file to be tracked and then to be committed by using git commit

lyggwtwtczxnhznebw
Jun 18, 2021

This is wrong. git add .gitignore creates the gitignore file. There is no gitignore before running that command, so you cannot add anything to it

celciuz
Aug 18, 2021

"git add .gitignore" does not auto create the .gitignore file. You will need to manually create the .gitignore file in your project root then run "git add .gitignore" to add it as a newly added git file to be tracked and then to be committed by using git commit

lyggwtwtczxnhznebw
Jun 21, 2021

I misunderstood. This is the correct answer. Disregard comment below

celciuz
Aug 18, 2021

"git add .gitignore" does not auto create the .gitignore file. You will need to manually create the .gitignore file in your project root then run "git add .gitignore" to add it as a newly added git file to be tracked and then to be committed by using git commit

zioalex
Jun 14, 2021

This is wrong. If you add the file before modifying it you need to re-add later. The correct sequence is: 1. Add config.json to the .gitignore 2. Run git add .gitignore 3. Run git commit

lyggwtwtczxnhznebw
Jun 18, 2021

This is wrong. git add .gitignore creates the gitignore file. There is no gitignore before running that command, so you cannot add anything to it

celciuz
Aug 18, 2021

"git add .gitignore" does not auto create the .gitignore file. You will need to manually create the .gitignore file in your project root then run "git add .gitignore" to add it as a newly added git file to be tracked and then to be committed by using git commit

lyggwtwtczxnhznebw
Jun 21, 2021

I misunderstood. This is the correct answer. Disregard comment below

celciuz
Aug 18, 2021

"git add .gitignore" does not auto create the .gitignore file. You will need to manually create the .gitignore file in your project root then run "git add .gitignore" to add it as a newly added git file to be tracked and then to be committed by using git commit

lyggwtwtczxnhznebw
Jun 18, 2021

This is wrong. git add .gitignore creates the gitignore file. There is no gitignore before running that command, so you cannot add anything to it

celciuz
Aug 18, 2021

"git add .gitignore" does not auto create the .gitignore file. You will need to manually create the .gitignore file in your project root then run "git add .gitignore" to add it as a newly added git file to be tracked and then to be committed by using git commit

lyggwtwtczxnhznebw
Jun 21, 2021

I misunderstood. This is the correct answer. Disregard comment below

celciuz
Aug 18, 2021

"git add .gitignore" does not auto create the .gitignore file. You will need to manually create the .gitignore file in your project root then run "git add .gitignore" to add it as a newly added git file to be tracked and then to be committed by using git commit

virnay1
Mar 11, 2024

Git add does not create the file but puts it in a staged state

gokula2010
Apr 8, 2021

Question asking us to select three options, so it should be 1. Add Config.json to the .gitignore file. 2. Run the git add .gitignore command. 3. Run the git commit command. If question asking to select four then it should be valid to choose recreate the repo as first item otherwise it should not be valid.

k4d
Aug 5, 2021

this is the correct answer. First you need to create this file manually, then add into git and commit change

erickim007
Jun 17, 2021

Guys, we do not need to but deleting repository is right thing to do because git cache and track changes. If you add .gitignore file to existing one, it does not likely affect your repository. If this answer option had 'git rm -r --cached', order would be 1. git rm -r --cached 2. git add .ignore 3. add config.json to ignore list 4. git commit However we don't have the option therefore the way we would do is; 1. delete repo & recreate with .gitignore as this is part of your step in creating repo 2. add config.json to ignore file list 3. git commit so given answer is correct.

kanak01
Jun 19, 2021

Why would you delete and re-create entire repository just to ignore a file ?

erickim007
Jun 21, 2021

if you don't want to, you would remove GIT cache. if you don't, adding .gitignore file would not have impact to your codeline therefore will keep check in your config.json file.

erickim007
Jun 21, 2021

if you don't want to, you would remove GIT cache. if you don't, adding .gitignore file would not have impact to your codeline therefore will keep check in your config.json file.

CheesusCrust89
Jun 28, 2021

this is only valid if that file has already been committed, which the question says nothing about. if it's untracked, adding it to the .gitignore and the git add git commit is enough.

Pamban
May 30, 2023

Moderator, please correct these answers. people are paying to these content and many members provide the evidence for the given answer is incorrect...

Mattt
Oct 9, 2024

The given answer is correct. You have alresdy commited the config file. Your commit stays in the history and config secrets leak to the git history.

Mattt
Oct 9, 2024

Sorry, we still haven't commited.

Mattt
Oct 9, 2024

Sorry, we still haven't commited.

syu31svc
Aug 9, 2022

A . gitignore file is a plain text file where each line contains a pattern for files/directories to ignore. So answer is 1) Add Config.json to the .gitignore file. 2) Run the git add .gitignore command. 3) Run the git commit command.

francis6170
Jun 26, 2021

Got this in the AZ-400 exam (June 2021).

Ravi22
Jun 6, 2021

1. Run git add .gitignore 2. Add config.json to the .gitignore 3. Run git commit

kanak01
Jun 11, 2021

Swap 1 and 2

Atos
Sep 21, 2022

"Delete and recreate the repository" - seems extremely harsh. Also it doesn't indicate that config.json was committed. I think we can rule this out. "git reflog expire" - this removes reflog entries, not really relevant. I think we can rule this out. So now just the ordering: 1. Run the git add .gitignore command - This will add the file for us to exclude config.json 2. Add Config.json to the .gitignore file - makes sense adding something in our empty file to exclude. 3. Run the git commit - This will add it to the repository.

randomaccount123
Mar 30, 2023

Wrong, git add will not add the file. It will just add it to the staging area if it already exists. If it doesn't you will get an error.

AKhalid
Feb 4, 2023

Verified correct answer is : 1-Add Config.json to the .gitignore file. 2-Run the git add .gitignore command. 3-Run the git commit command.

dipti927
Jun 8, 2023

Correct Answer : Add Config.json to the .gitignore file. Run the git add .gitignore command. Run the git commit command.

yana_b
Sep 25, 2023

Provided answer is correct: https://learn.microsoft.com/en-us/azure/devops/repos/git/ignore-files?view=azure-devops&tabs=visual-studio-2022 Entries in a .gitignore or exclude file have no effect on files that Git already tracks. Git tracks files that you've previously committed. To permanently remove a file from the Git snapshot so that Git no longer tracks it, but without deleting it from the filesystem, run the following commands: git rm --cached <file path> git commit <some message> Then, use a .gitignore or exclude file entry to prevent Git from reporting changes to the file. We do not have the above options amongst the answers => delete & recreate the repo should be the 1st step.

Mattt
Oct 9, 2024

Correct answer

UrbanRellik
Oct 12, 2024

1. Git add .gitignore 2. Add config.json to the .gitignore file. 3. git commit

Jamboon
Apr 3, 2021

Do you really need to recreate the repo?

veselin465
Apr 3, 2021

I was also surprised by that, so i did a little research It looks like that the rules in .gitignore file only apply to untracked files. And according to the question, the config file has never been added in a commit, so it should be untracked, therefore there should not be a reason recreating the repo. One thing is sure, if the config file was actually tracked, then recreating would have been the only LISTED thing in this question you can do to untrack it (but of course there are better ways to do it). All this information came mainly from a stackoverflow discussion: https://stackoverflow.com/questions/7927230/remove-directory-from-remote-repository-after-adding-them-to-gitignore

aroravibhu
Dec 23, 2021

1. Git Ignore command. 2. Add Config.json to the .gitignore file. 3. Run the git commit command. Run the git commit command. https://docs.microsoft.com/en-us/azure/devops/repos/git/ignore-files?view=azure-devops&tabs=visual-studio

UnknowMan
May 10, 2022

- Add manualy a gitignore file (git add .gitignore just add a file named .gitignore, is not a build in command) - Add Config.json to the gitignore file - Run git commit

Eltooth
May 20, 2022

Run the git add .gitignore command Add Config.json to the .gitignore file Run the git commit command https://stackoverflow.com/questions/10744305/how-to-create-a-gitignore-file#:~:text=gitignore%20file%20is%20not%20added,commit%20%2Dm%20%22message%22%20.

Eltooth
May 22, 2022

On labing this with Git you cannot run "git add .gitignore" command if the .gitignore file does not exist. So you either manually create the .gitignore file first then add config.json file to it, or follow steps that @Sylph suggests at top of page.

randomaccount123
Mar 30, 2023

I think some people are getting confused and thinking git add .gitignore will add the file. It doesn't. That will just add the file to the staging area if it already exists. If it doesn't exist you will get an error. You therefore need to add config.json to the file first and then run git add to add it to the staging area. Then obviously once its in the staging area you can the commit it.

xRiot007
Jul 28, 2023

Answer is : 1. Add the config file to the git ignore file 2. Run git add to add the change to staging 3. Run git commit to commit all staged changes.

vsvaid
Dec 23, 2023

1. Add config.json 2. Run git add .gitignore 3. Run git commit

megleg
Sep 4, 2024

1. Add config.json to the .gitignore 2. Run git add .gitignore 3. Run git commit

wahabajasco
Jan 30, 2025

It should be: 1. Manually create the .gitignore file and add the config.json - Add Config.json to the .gitignore file. 2. Run the "git add" command to stage the newly created .gitignore file - Run the git add .gitignore command. 3. Commit the staged changes - Run the git commit command.