Please check this Git cheat sheet for a quick overview.
To initialize a new project, initialize a git repository.
git init
The command above is not needed in our case because you will already get it set up with the right directory, so please do:
git clone git@gitlab.mi.hdm-stuttgart.de:mad1/mad1.pages.mi.hdm-stuttgart.de.git
Hint: Replace the location of the remote repository to the one which you have access to. If you use SSH make sure your keys are set up correctly.
After initializing you are automatically on the main/master branch. Now we are going to start working in the repository by creating a new file in there called "INTRODUCTION.md".
You can check the status of the files in a directory to display if there are untracked or modified ones:
git status
Currently, git does not track this file so tell git that the file exists call:
git add INTRODUCTION.md
And then you can do a commit so git keeps track on that:
git commit -m "Added a INTRODUCTION.md"
While working on a team, we have a remote repository. In our case this is hosted on the HdM Gitlab.
So now that we have our changes locally we want to push them to the remote repository:
git push origin master
It could also be that team members made changes, and you want to check them:
git fetch origin
The above will only fetch information about the changes, to get the changed code call:
git pull
Now that you are in a team, each team member works on a different feature of the application in their own space but with the main/master branch as their base:
git branch feature1
You can check out existing branches by:
git branch
If you want to switch a branch you can call:
git checkout feature1
Let's assume you did your work on feature1 branch, you added files and commited them, then you want to merge that branch to main/master because you want to make a production release. So first you want to switch to master branch:
git checkout master
And then merge the feature1 branch:
git merge feature1
This merge is only locally so if you want the changes in remote you have to push again or directly merge to master: git merge origin/master
. If you are not using a branch anymore you can delete it.
If you have issues using git in command line you can of course use any git clients. There are multiple ones on the market, so here are popular ones: