PatrickVideos AzureDevOps Repos GIT VisualStudio Developers 2022
PatrickVideos AzureDevOps Repos GIT VisualStudio Developers 2022
FOR DEVELOPERS
1
copyright PatrickVideos.com
Table of Contents
What is Azure DevOps Services?................................................................................................................... 4
Connecting to Azure DevOps (VSTS) ............................................................................................................. 6
Install GIT .............................................................................................................................................. 6
Create an Azure DevOps Project ........................................................................................................... 8
Troubleshooting connection / Proxy Issues .................................................................................................. 9
Add your project to source control............................................................................................................. 10
Create a local Git repo for your project .............................................................................................. 10
Publish your code to Azure Repos ...................................................................................................... 11
Git workflow................................................................................................................................................ 14
Create a Branch........................................................................................................................................... 15
To create a branch in the cloud .......................................................................................................... 15
To View the branch created in the cloud in Visual Studio .................................................................. 15
Delete a Branch ................................................................................................................................... 17
Clone Repository ......................................................................................................................................... 18
Save work with commits ............................................................................................................................. 20
Different types of Commits ................................................................................................................. 21
Edit files on the web ........................................................................................................................... 24
Update code with fetch, pull and sync ....................................................................................................... 25
Pull ...................................................................................................................................................... 27
Sync ..................................................................................................................................................... 27
Stage changes ..................................................................................................................................... 28
gitignore to prevent tracking of files .......................................................................................................... 29
Review history............................................................................................................................................. 30
Revert .................................................................................................................................................. 31
Amend your last commit..................................................................................................................... 32
Update your branch with the latest changes from master ........................................................................ 33
Resolve Merge conflicts .............................................................................................................................. 35
Review your code with Pull request ........................................................................................................... 36
Code review ........................................................................................................................................ 38
Branch Policies and Branch Security ........................................................................................................... 40
Managing Team members and access ........................................................................................................ 41
2
copyright PatrickVideos.com
Git Tags ....................................................................................................................................................... 42
Git Stash ...................................................................................................................................................... 43
Copy changes with cherry-pick ................................................................................................................... 45
3
copyright PatrickVideos.com
What is Azure DevOps Services?
4
copyright PatrickVideos.com
Microsoft renamed Visual Studio Team Services (VSTS) to Azure DevOps Services.
Build & release Azure Pipelines Continuous integration and continuous delivery (CI/CD) that works with any language,
platform, and cloud.
Code Azure Repos Unlimited cloud-hosted private Git and Team Foundation Version Control (TFVC)
repos for your project.
Work Azure Boards Work tracking with Kanban boards, backlogs, team dashboards, and
custom reporting.
Test Azure Test Plans All-in-one planned and exploratory testing solution.
Packages Azure Artifacts Maven, npm, and NuGet package feeds from public and private sources.
(extension)
With Azure DevOps Services you gain an integrated set of services and tools to manage your
software projects.
Additional details
https://docs.microsoft.com/en-us/azure/devops/user-guide/services?view=vsts&tabs=new-nav
https://docs.microsoft.com/en-us/azure/devops/repos/git/gitquickstart?view=vsts&tabs=visual-studio
5
copyright PatrickVideos.com
Connecting to Azure DevOps (VSTS)
Install GIT
Download and install git from here. Keep all the defaults.
https://git-scm.com/download/win
https://docs.microsoft.com/en-us/azure/devops/learn/git/install-and-set-up-git
6
copyright PatrickVideos.com
7
copyright PatrickVideos.com
Create an Azure DevOps Project
Search for Azure DevOps and using a Microsoft account create a free azure DevOps trial.
Create a project, set version control to GIT and Work item process to scrum. Click Create.
8
copyright PatrickVideos.com
Troubleshooting connection / Proxy Issues
If you work in a corporate environment and unable to connect, you may have proxy issues.
** Only do this if you are behind a firewall and use a proxy server to connect.
Go to your C:\Users\[yourid]\.gitconfig
And edit the file as follows. [Your proxy address] fill in with your proxy address.
9
copyright PatrickVideos.com
Add your project to source control
Create any project. Shown below are steps to create a web application and select MVC project.
**The below step need to be done by only one person in your team.
Right-click on your solution in Solution Explorer and choose Create Git Repository.
10
copyright PatrickVideos.com
Publish your code to Azure Repos
11
copyright PatrickVideos.com
**Your code is now in a Git repo in Azure Repos. You can view your code on the web.
You can view/manage the security of your code as show in the screen shots below.
12
copyright PatrickVideos.com
13
copyright PatrickVideos.com
Git workflow
1. Create a branch for the changes you plan to make and give it a name. For more
branching guidance, see Adopt a Git branching strategy
2. Commit changes to your branch. People often have multiple commits for a bug fix
or feature.
3. Push your branch to the remote repository.
4. Create a pull request so other people can review your changes. To incorporate
feedback, you might need to make more commits and push more changes.
5. Complete your pull request and resolve any merge conflicts from changes other
people made after you created your branch.
14
copyright PatrickVideos.com
Create a Branch
Git branches aren't much more than a small reference that keeps an exact history of commits, so
they are very cheap to create.
15
copyright PatrickVideos.com
2. Click Git -> Fetch
You will see the branch created in the cloud under remotes/origin.
3. To work on that branch Right Click on the branch and click checkout
16
copyright PatrickVideos.com
Delete a Branch
To delete a branch, right click and click Delete. Deleting a branch locally will not delete it remotely.
**Make sure the branch is not checked out (bold), before deleting.
17
copyright PatrickVideos.com
Clone Repository
If you join an existing project, you will need to create a complete local copy of an existing Git
repo by cloning it. Cloning a repo downloads all commits and branches in the repo and sets up
a named relationship with the existing repo you cloned. Use this relationship to interact with the
existing repo, pushing and pulling changes to share code with your team.
18
copyright PatrickVideos.com
Additional details
https://docs.microsoft.com/en-us/azure/devops/repos/git/clone?view=vsts&tabs=visual-studio
19
copyright PatrickVideos.com
Save work with commits
Git tracks file changes in your repo as you work, and separates the files in your repo into
three categories:
• Unmodified files - These files haven't changed since your last commit.
• Modified files - These files have changes since your last commit, but you haven't yet
• Staged files - These files have changes that will be added to the next commit
20
copyright PatrickVideos.com
Different types of Commits
1. Commit All will make record of the changes that you have made to your local branch. It
will not mark the change in the remote repository.
2. Commit All and Push will do the above and push it to the remote repository. This means
that any changes you have made will be saved to the remote repository as well.
3. Commit All and Sync does three things. First, it will commit. Second, it will perform a
pull (grabs the updated information from the remote repo). Finally, it will push.
21
copyright PatrickVideos.com
In the Git Changes window (View -> Git Changes)
22
copyright PatrickVideos.com
You can now view your changes on the web.
23
copyright PatrickVideos.com
Edit files on the web
You can also edit the files on the web (Not recommended)
24
copyright PatrickVideos.com
Update code with fetch, pull and sync
Update the code in your local repo with the changes from other members of your team using
the following commands:
• Fetch: downloads the changes from your remote repo but does not apply them to
your code.
• Merge: applies changes taken from fetch to a branch on your local repo.
• Pull: is a combined command that does a fetch and then a merge.
• Sync: is a combined operation of pulling remote changes and then pushing local ones,
synchronizing the commits on the local and remote branch.
25
copyright PatrickVideos.com
You will fetch and sync your code regularly to see or incorporate the code of your team members.
26
copyright PatrickVideos.com
Double click on the files under incoming to view the code that is coming in.
If you are satisfied with the incoming files, you can either click Pull or Sync.
Pull will only pull the incoming code. It won’t push your changes to the remote repo.
Sync is a combined operation of pulling remote changes and then pushing local ones (only
those committed to local branch) , synchronizing the commits on the local and remote branch
27
copyright PatrickVideos.com
Stage changes
If you don’t want to commit all of your changes, then select only the files you want to commit
by staging them.
Once staged you can them click Commit Staged and Sync
28
copyright PatrickVideos.com
gitignore to prevent tracking of files
If you don’t want to track certain files like your config files, you can ignore them.
For previously committed files, to ignore them going forward, go to the directory of the file using GIT
CMD or GIT Bash and run the below command as shown
https://docs.microsoft.com/en-us/azure/devops/repos/git/ignore-files?view=azure-
devops&tabs=visual-studio#permanently-ignore-changes-to-a-file
29
copyright PatrickVideos.com
Review history
Review commit history to find out when file changes were made and determine differences
between versions of your code. To view History right-click on the branch.
30
copyright PatrickVideos.com
Revert a commit as shown
31
copyright PatrickVideos.com
Amend your last commit to correct small errors without making a new commit.
32
copyright PatrickVideos.com
Update your branch with the latest changes from master
Before creating a Pull request to merge the code from your remote branch, into the remote master
branch, we must make sure our branch is in sync with the master branch.
33
copyright PatrickVideos.com
(4) To do that right click on master and select Merge From
34
copyright PatrickVideos.com
Resolve Merge conflicts
When you merge one branch into another or when you sync your branch, file changes from
commits in one branch can conflict with the changes the other. Git attempts to resolve these
changes by using the history in your repo to determine what the merged files should look like.
When it isn't clear how to merge changes, Git halts the merge and tells you which files conflict
35
copyright PatrickVideos.com
Review your code with Pull request
The pull request is the collaborative process that lets the rest of the team discuss changes in a
branch and agree to merge them once everyone approves. Use pull requests to get early
feedback from others on work in progress, even if you're not ready to merge the changes into
another branch.
36
copyright PatrickVideos.com
37
copyright PatrickVideos.com
Code review
38
copyright PatrickVideos.com
What is a squash merge?
Squash merging is a merge option that allows you to condense the Git history of topic branches
when you complete a pull request. Instead of each commit on the topic branch being added to
the history of the default branch, a squash merge takes all the file changes and adds them to a
single new commit on the default branch.
39
copyright PatrickVideos.com
Branch Policies and Branch Security
Branch policies help teams protect their important branches of development. Policies enforce
your team's code quality and change management standard.
Additional details
https://docs.microsoft.com/en-us/azure/devops/repos/git/branch-policies?view=vsts
40
copyright PatrickVideos.com
Managing Team members and access
Add members to your project in Azure DevOps, so you can share code and work with your team
Additional details
https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/add-team-
members?view=vsts&tabs=new-nav
41
copyright PatrickVideos.com
Git Tags
Additional details
https://docs.microsoft.com/en-us/azure/devops/repos/git/git-tags?view=vsts&tabs=new-nav
42
copyright PatrickVideos.com
Git Stash
If you are working on a user story, but you’re not ready to commit, but at the same time you want to
save the code for now and look at the original branch without changes - Stash the changes.
43
copyright PatrickVideos.com
If you want to bring the stash you can Apply or Pop the stash. Or Drop it if you don’t want it.
Pop will also apply the stash and delete the stash.
If some of your files were previously staged, you may elect to keep them staged or un-stage them all.
44
copyright PatrickVideos.com
Copy changes with cherry-pick
Copy commits from one branch to another using cherry-pick. Unlike a merge or rebase, cherry-pick only
brings the changes from the commits you select, instead of all the changes in a branch.
•Accidentally committing on the wrong branch. Cherry-pick the change(s) over to the correct branch
and then reset the original branch to the previous commit.
•Pulling out a set of commits made in a feature branch so you merge them back to your master branch
sooner.
•Porting in specific commits from the master branch without rebasing your branch
1. Changes are made to a branch UserStory1 and committed either locally or synched.
2. We want these changes(commits) from UserStory1 into branch UserStory2, so checkout branch
UserStory2.
3. Right-click the commit you want to cherry-pick and select Cherry-pick.
4. Visual Studio will copy the changes made in that commit into a new one on your current branch
https://docs.microsoft.com/en-us/azure/devops/repos/git/cherry-pick?view=azure-
devops&tabs=visual-studio
45
copyright PatrickVideos.com