git workflow

Since the usage of git is not easy to understand at the first glance, I’d like to list the most important git commands here once again.

Initial configuration (needs to be done only once)

Create an SSH key and upload it to Gitlab

ssh-keygen

Confirm all questions by hitting return. Show the generated public key by calling: cat ~/.ssh/id_rsa.pub

Copy the output and paste it on GitLab (User -> Settings -> SSH Keys).

Configure user name and email

$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com

The user name and email will show up as the author’s information for the commits. They are not used for authentication. Hence, you do not need to use your university email account.

Clone the repository

Go to the repository on the GitLab web page, click on clone, and copy the SSH link. Run git clone <REPO> (replacing <REPO> by the copied SSH link).

Set default pull behavior

You probably want to set the default behavior of git pull to use rebase: git config --global pull.rebase true

Synchronizing the repositories

To add new or modified files from workspace to staging, run git add To update your local repository, call git commit -m “<TEXT>“ (replacing <TEXT> with a meaningful message describing your change).

If you only want to commit already tracked files, you can run git commit -a -m “<TEXT>“ to commit all files at once.

If you want to update the remote repository to the same state as your local one, run git push

Status information and troubleshooting

View the current state

In order to monitor the current state of the repository and retrieve information about potential operations, call git status To check the current difference between your workspace and the local repository, run git diff To check the commits on your local repository, call git log To check the commit history of the remote repository, run git log origin

Troubleshooting

If a call of git push fails with an error message like ! [rejected] main -> main (fetch first) you should run a git pull first.

If you have made local changes, you can run git restore <FILE> to restore the version of file <FILE> in your workspace to the same version as in your repository.

teaching



Categories: ["teaching", "ss24", "dissys"]