To start, you will need to install git on your machine, if you don't have it already.
To test, open the Command-Line or Power Shell and type git.
If you have it installed, the output should look something like this.
PS C:\> git
usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]
These are common Git commands used in various situations:
start a working area (see also: git help tutorial)
clone Clone a repository into a new directory
init Create an empty Git repository or reinitialize an existing one
work on the current change (see also: git help everyday)
add Add file contents to the index
mv Move or rename a file, a directory, or a symlink
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index
In case you need to install it, go to git-scm and choose your OS version.
After the installation is finished, reopen all console windows and try to run the git command once again. This time you should have the previous output.
With an SSH key you will be able to do any git operation between your machine and the remote git server without writing your username or password, or if you choose, just the password.
The process to create the key on your machine is simple (As described in Github Help ):
Open Git Bash
Paste the text below, substituting in your GitHub email address.
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location. The output should be similar to :
Enter a file in which to save the key (/c/Users/you/.ssh/id_rsa):[Press enter]
When you're prompted to "Enter passphrase", if you leave it black, you won't need to add the password on git operations. It's highly recommended to set a password!
Now that you have created an SSH key, you need to add it to DevOps.
Locate the .ssh folder where the keys are located. If, on step 3 you choose the default location, the location should be "C:\Users[yourWindowsUsername].ssh".
Inside this folder, you will find a file called "id_rsa.pub". Open this file with nodepad.exe and copy the content to the clipboard.
Go to DevOps and click on your avatar, top right, and select Security option and then, on the left menu, select "SSH public keys".
At this point, you should see all your previously added key and an Add button that you need to click and insert your SSH public key stored on the clipboard.
At this point you have your SSH key created. ๐ ๐
Now that you have git installed and running on your machine, you will need to get the source files.
First, locate the project inside DevOps and then go to Repos.
On the top right side of the window, you will find the clone button.
Now you have three options to manage your local repositories :
For the sake of simplicity, you will use the third option, Visual Studio built-in functionality.
Follow the following steps to clone the project:
After this, you should have all the files on your local machine.
You can open the project and start doing your changes.
Either if you clone a new project or if you are starting a new story on an old project, you will probably need to create a new branch to isolate your changes.
To create a new branch follow the steps:
At this point, you have your new branch created and checked-out, and you can start doing your changes.
Now that you've made some changes, you will need to commit those changes.
To do that, go the Team Explorer tab, and select home (small house icon).
At this point you should be able to see all uncommitted files, that were changed since the last commit.
To commit follow the steps:
After these steps, the files should disappear.
Now that the changes are committed, you need to send your changes to your remote branch.
If more than one person is working on the same branch, there is a risk that your local branch is behind by a few commits.
This means that you first need to pull all changes, merge them on to local branch, solve all merge conflicts if any, and then finally push them.
On Team Explorer, go to Sync and you will see only your changes.
It looks like you have your branch updated with the remote branch.
But if you click on Fetch you will check if the remote branch has any changes.
And if you have select Pull, and there are no conflicts, the changes from the remote branch will be merged into your local branch.
Now that your local branch is updated with your remote one, you can push your changes, clicking on Push.
Once you pushed your branch to your remote branch, you may need to have a code review from one of your peers, to make sure that your code won't break the parent branch.
Azure DevOps, like many other Git providers, offers a functionality called Pull Request.
This allows you, to request a review of your code, and if there are no problems to be merged into the parent branch.
To create a Pull Request on Azure DevOps follow the steps:
When you are working on a team, there is a chance that another person, changed the same section of code. When this happens, and you try to merge the two pieces of code, git doesn't know which piece should be kept, and will trigger a merge conflict.
To solve the Merge Conflict follow the following steps:
If for some reason, you add some changes to the wrong branch, and they are not committed yet, you can move them to another branch.
To do this follow the steps: