In order to be able to begin the version control of your code/project, you need to initiate the tracking.
- Under the
practicalfolder, open a git terminal- on Windows : right-click ->
Open git bash here - on MAC / LINUX : Open the computer terminal and change the current directory to
practical
- on Windows : right-click ->
Hint for MAC users :
To list directories in the current folder, write down
lsTo change the current directory, write down
cd path/to/folder
- Configure your git to follow the branch naming convention.
This convention has recently changed to call 'main' instead of 'master' the default branch of the git repo.
Write down the following command to force git generating the default branch with the name 'main' :
git config --global init.defaultBranch main
This configuration is a global configuration. Once done, you don't have to do it again on this computer. But if you change the computer, you'll need to do it again.
- Write down
git initin the terminal ; it creates a hidden.gitfolder where commits will be stored.
- The
practicalfolder contains 2 files : an ImageJ macro and a README.md file. Let's add them in the history.
-
On the git terminal, write down
git add .to add them in the temp buffer. -
Write down
git commit -m "initiate git version control"to add them in the history
Note:
-mindicates that you are adding a message to the commit. It's important to write a clear and concise message in order to know what has been changed. The commits, if the project becomes public or if you collaborate on projects, will be accessible by others and they should also be able to understand what has been done thanks to the message you've written.
- Under the
practicalfolder, open the README.md with a text editor (it can beTextEdit,NotepadorNotepad++) - The README is missing a welcome message. Let's correct it by adding it, with the workshop logo. Copy the following lines at the very beginning of the README and save it.
Welcome to the Git & GitLab Workshop !
<img src="icons/banner-image.png" width="30%">
- Do a commit with a pertinent message (example: Update README with course visual guidlines)
- It's important to know what is the last commit you have locally and also to review all the commits you did before a release.
On the terminal, write down
git log. You should see 2 commits.
Hint: if your have a lot of commits, you can use the bottom arrow of your keyboard to see more. To exit the log view, simply press q
- There are files that should not be tracked because they are too heavy, they are not relevant for the project or they should not be shared.
This is typically the case for hidden files like
.DS_StoreorThumbs.dbor for data files, like images.
- Under the
practicalfolder, create a new file called .gitignore
Note: Right-click -> New text file and then rename it as .gitignore
-
Open this file with a text editor like
Notepad,Notepad++orTextEdit -
Add the following list of files to ignore in the .gitignore and save it.
.DS_Store
Thumbs.db
- Move the folder
datainside the folderpractical. This folder contains test images for the ImageJ macro. We don't want images to be tracked by git. So, add this folder in the .gitignore and save it.
/data/
- Commit the changes with a pertinent message (ex: "adding gitignore")