before we set up our git repo, lets make sure that we have git installed, type in git --verion
I have version "git version 2.27.0.windows.1" Installed, should you not have git installed got to https://git-scm.com/downloads and install the version for whatever os you are working with.
to set up our repo navigate to the root folder of our solution and type in git init
Generally I prefer to rename my master branch to prod for production because I like to have four main branches that are linked to CICD pipelines and those are dev, test, stage, and prod, thus I name my branches accordingly to minimize confusion.
initially you can just do a git checkout -b prod if you decide to change it later, it can be done but may be a bit of a pain in the arse.
now before you check anything in it is imperative that you create a git ignore file, this is because whenever you are working with a framework there are potentially hundreds of megabytes of generated/compiled files that you do not want up in your remote repo or even in your local one.
you can right click in the root of your project and create a new file called .gitignore or you can simply type in new-item .gitignore -itemtype file into your terminal like so
either one will result in an empty .gitignore file being created in your solution root
now with that complete lets past in the two git ignores
for visual studio senior
https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
for visual studio code
https://github.com/github/gitignore/blob/master/Global/VisualStudioCode.gitignore
i just put one after the other
I know it's ridiculously long and the vs code stuff is only the last 20 lines or so, but if we are going to open our project in visual studio senior, lets cover those bases too.
now as soon as you save your .gitignore file
you immediately see a reduction in the number of files that need to be checked in, so lets go ahead and do that.
and that's it first we did a "git add ." to stage all of our files for a commit next we executed "git commit -m 'initial checking'" to checkin all of the changes we had staged. Now all that is left to do is to push our changes to a remote repository.
let's create a remote repo, I'm going to make mine in Microsoft's devops
hit the New project button and fill out the relevant details
simple enough, after that navigate to the repos section in your devops
once there copy the git command to configure your upstream and execute it in your terminal
this will push your code up to your repository, we can navigate to our repo in devops to see our code base.
and voila, we have a remote repository.
next lets annotated it, mark this commit as special so that we can always come back to it in the future. to do so lets create a tag
git tag -a v1.0.0 -m 'initial commit'
You can think of this as a bookmark, usually when you have a project you will have hundreds if not thousands of check ins, by marking one with a tag we are just saying that this one is special, how special you may ask well that is what you specify in the message.
next lets push the tag up to our remote
git push --tags
simple as that, now our tags are stored in our remote repository and available to anyone who makes a pull request.
to view our existing tags locally in our terminal you can execute
git tag -n
to see a list of all the existing tags with their annotations.
finally before we wrap this post up lets create a dev branch and push it upstream
simply type in
git checkout -b dev
then
git push
which will prompt you that this branch doesn't exist in the remote repo and needs to be created by executing the command
git push --set-upstream origin dev
and simple as that now we have a dev and prod branch, you can go ahead and do the same thing for test and stage if you would like, but I'm not sure if it will be necessary.