[MUSIC]
>> Hello everyone. I'm [inaudible].
I'm one of the PMs working on Visual Studio,
and today I would like to talk to you about some tips and
tricks for the Git tooling and Visual Studio 2022.
Let's get started by looking at stashing in Visual Studio.
Stashing is a useful feature
when you have changes that you are not ready to
commit and need to switch and work on something different.
To stash your changes in Visual Studio,
open the Git Changes window,
provide your stash message,
and then use the Commit All drop-down,
choose to Stash All.
This is your stash.
When you are ready to go back to your changes,
right-click on your stash and choose
Apply or Pop depending
on if you would like to keep your stash or not.
In this case, I don't need to keep my stash,
so I'll use the Pop option,
and this is our change.
Next I'm going to be talking to you about adding
other remote repositories to your Git repository.
Git calls the remote repository you clone from origin.
Sometimes you need to add
other remote repositories to collaborate with others.
To other image repository,
you first need the repository URL.
In this example, I'm going to use
the repository that I have forked from as a remote repository.
A quick way to get the URL is to use
the additional menu on the side and click on "Open in Browser."
Once you do that, your browser should open and take you
to the GitHub page where that repository is hosted,
and then you will just need to click on the "Forked from link",
which will take you to the original repository.
Once you get there,
just get the repository URL,
and then go back to Visual Studio,
click on the "Additional operations
link" and click on "Manage Remotes."
You'll see that my origin is already there,
and so what I will need to do now is click on "Add" and
paste the URL that we have just copied from the browser,
and I'm going to name this a Forked_From.
Then feel free to save,
click "Okay", and then just fetch.
Once you do that, Visual Studio automatically adds
in the other repository as an additional remote repository.
Next, I would like to talk to you about getting updates
from branches other than you're tracking branch.
Getting updates from branches
other than your remote tracking branch is
useful if you need to get
the latest updates that your colleagues have been working on,
or if you are working on a fork and need to get
updates from the original repository that you forked from.
A quick way to do that in Visual Studio is by utilizing
the branch picker on the Git changes window or the status bar.
By clicking there,
going to the Remotes tab,
right-clicking on the "Remote
branch" and then choosing "Merge Into Current Branch".
In this case, I'm going to be getting
the latest updates from Main on
the original repository that I
have forked from into my local Main.
Once you do that, you get a success message indicating that,
that has been successful.
To speed up your flow,
you can pin the branches that you are actively working on
by right-clicking on any branch and selecting pin to top.
If you just need to get to a remote tracking branches updates,
it's easier to use the Pull from
feature in the additional operations mineral.
Now, let's review the latest updates
by clicking on the outgoing incoming link.
Doing that opens the Git repository window where you can see
the latest updates that we have been
able to get from the other remote branch.
Feel free to double-click on any one of these commits and
browse the different commits by looking
at the commit details and the def next to it.
Once you are ready,
feel free to click the "Push" button to
push all the latest changes into your remote branch.
Next, I would like to talk to you about
cleaning up your commits using the squash feature.
It is a good practice to commit regularly.
As you can see here,
I've been working on a bug-fix and ended
up completing the work with two commits.
Visual Studio can combine these two commits and
clean up the Git history through the squash feature.
To do that, use the Control key on
your keyboard to select
the commits that you would like to combine,
right-click, select Squash Commit.
That would bring up the squash dialogue,
which would allow you to update your commit message.
In this case, we can say that we are fixing our bug,
and then click "Squash",
and Visual Studio combines both commits for us.
Now we can go ahead and
push our clean history to our remote branch.
Finally, the last tip that I would like to
share with you today is on Git settings.
If you need to change the behavior of
the Git tooling in Visual Studio,
there's a high chance that you can do
that using the Git settings functionality.
A quick way to get to
your Git settings is through the top-level Git menu,
by clicking on "Settings".
Once you're in there, you'll be able to change
your Global repository settings and your Git repository settings.
For example, I can change my e-mail address,
enable force pushing, and
even tweak and change how
Visual Studio behave when switching between repositories.
On the repository sitting page,
I get the ability to edit my ignore and attributes files as well.
Clicking "Edit" here would open
my.gitignore file where I can make any tweaks I need to make.
Thanks everyone for listening.
I hope this was helpful and informative.
Make sure to check more of
our VS 2022 videos and see you around. Bye.