Follow these steps to clone a repo, make file changes, and commit them to GitLab.
cd <DIRECTORY_NAME>
git clone <REPO_URL>
The Command Prompt clones the files from the repo into the specified location.
Create and check out a branch to commit to. When making changes, never commit directly to the master branch! Instead, check out the code and make changes to it. Then, test and request reviews through a merge request (MR). Once approved, merge them to develop and then to master.
Run the following command to create a new local branch:
git checkout -b <NEW_BRANCH_NAME>
The following output should appear in the terminal:
Switched to a new branch <NEW_BRANCH_NAME>
You're now ready to make changes to the repo files you've cloned:
You can now use the Command Prompt to add these changes to Git.
git status
You may notice that some directories aren't added to Git by default. This is due to the presence of a .gitignore file, which ignores any files that don't need to be pushed to Git by default.
git add <NAME_OF_FILE_WITH_CHANGES>
Alternatively, if there are multiple files that need to be added, you can use git add . to add them all at once.
Now that files are added to Git and you checked the status, commit the files:
git commit -m <MESSAGE_RELATED_TO_THE_CHANGES>
git status
The terminal should say: Nothing to commit, working tree clean. You've just successfully committed to the branch you created. This is all in your local Git repository, and needs to be pushed to update GitLab. Remember, the best practice is to commit often. Think of a commit as saving your progress.
Now that you've made local commits, push them into the repository in GitLab.
Run the following command:
git push --set-upstream origin <NEW_BRANCH_NAME>
Congratulations! You've synced up the GitLab repo with your local Git changes.