Creating a New Git Repository using PowerShell
For this example, I will use the directory
git
and thesubdirectory
‘portfolio’, which will become my new repository on GitLab.
Creating Directory and Subdirectory
Note
Some individuals use the flag-force to ensure that both the Git and Portfolio directories are created if they don’t already exist; however, this is a step I’ve never required and thus will not include it here.
List directories
Will show the following output:
Convert Portfolio into a Repository
- Change directories
- Initiate project
A .git folder is created in the directory that contains Git records and configuration files. To ensure that your repository works as intended to not edit these files.
Add a remote
Adding a remote will tell Git that your new remote repository is tied to the portfolio folder.
Create README file
Though you can create any file or any amount of files to initiate your repository, the best practice is to create a README.md file. The README.MD file should provide essential information that helps others understand the project in it, how to use it, and how to contribute to the project if you accept contributions.
Prepare for First Commit
- add README.md file.
git add
moves changes from the working directory to the staging area and tells Git which modifications (added, modified, deleted files) you want to include in your next commit.
- Commit Files
git commit
takes the added files and creates a new commit representing the changes in the repository’s history.
-m
Every commit requires a commit message; write meaningful commit messages that communicate the intent of the changes.
-S
will prompt you to sign your commit. For additional information see Setting up GPG Keys with Powershell
- Push Files
git push
uploads local repository content to a remote repository.
--set-upstream origin master
Sets the default upstream (remote) branch for the current local branch.
origin:
This specifies the remote repository where you’re pushing your changes.
master:
This specifies the branch you’re pushing to on the remote repository.
Note
Main or other names are now being used as the default branch to avoid the master-slave terminology
- Celebrate
Congratulations! Your project is ready; you can confirm visually by visiting your GitLab page.