Best Practicesยท3 minutes read

Git Start for All Levels: from Begginer to Advanced

This post will be about how to start using git. Also, I will add some ๐—ถ๐—ป๐˜๐—ฒ๐—ฟ๐—ฒ๐˜€๐˜๐—ถ๐—ป๐—ด ๐˜€๐˜๐˜‚๐—ณ๐—ณ for ๐—บ๐—ถ๐—ฑ/๐˜€๐—ฒ๐—ป๐—ถ๐—ผ๐—ฟ folks too and it will be marked with double asterisk (*). if it overwhelms you feel free to skip those parts, so let's go!

Linas Kapoฤius

Linas Kapoฤius

Solutions Architect at Corgineering.com

January 14, 2025
Git Start for All Levels: from Begginer to Advanced

1๏ธโƒฃ ๐—ก๐—ผ ๐˜๐—ผ๐—ผ๐—น ๐—ป๐—ผ ๐—ด๐—ฎ๐—ถ๐—ป: Download and install Git from git-scm.com. Itโ€™s available for Windows, macOS, and Linux.

** Check out Git extension Git LFS, it uses pointers in your Git repository to track large files, replacing the actual file content with lightweight references.
2๏ธโƒฃ ๐—–๐—ผ๐—ป๐—ณ๐—ถ๐—ด๐˜‚๐—ฟ๐—ฎ๐˜๐—ถ๐—ผ๐—ป: Set up your username and email to associate with your work:

git config --global user.name "Your name"
git config --global user.email "your_email@example.com"


** Majority of the time we are using: ๐š๐š’๐š ๐šŒ๐š˜๐š—๐š๐š’๐š --๐š๐š•๐š˜๐š‹๐šŠ๐š•. There is no need to write --global flag if you want to make separate configurations for every repo.

3๏ธโƒฃ ๐—œ๐—ป๐—ถ๐˜๐—ถ๐—ฎ๐—น๐—ถ๐˜‡๐—ฒ ๐—ฎ ๐—ฅ๐—ฒ๐—ฝ๐—ผ๐˜€๐—ถ๐˜๐—ผ๐—ฟ๐˜†: Start tracking a project with Git (on your wanted directory):

git init

** Running ๐š๐š’๐š ๐š’๐š—๐š’๐š on an existing repository doesnโ€™t overwrite it. Instead, it simply reinitializes the .git directory. This can be helpful if your .git folder gets corrupted or if you want to recover a partially deleted Git setup

** Git allows you to customize new repositories by using templates:

git init --template=/path/to/template_directory

**A bare repository doesnโ€™t have a working directory and is often used for remote repositories on popular tools like GitLab, GitHub:

git init --bare

4๏ธโƒฃ ๐—ฆ๐˜๐—ฎ๐—ด๐—ถ๐—ป๐—ด: Prepares and checks your changes before saving them in Git. Symbol ( . ) in this case means that we are preparing and changing all modified or created files in the directory. We are staging/preparing just in case not all changes we want to save/snapshot (later definition ๐—ฐ๐—ผ๐—บ๐—บ๐—ถ๐˜):

git add .

After that you can check how repository is changed by using status command:

git status

** With ๐š๐š’๐š ๐šŠ๐š๐š, Git ignores files listed in .gitignore, but you can force-add them with

git add -f

** Using ๐š๐š’๐š ๐šœ๐š๐šŠ๐š๐šž๐šœ --๐š’๐š๐š—๐š˜๐š›๐šŽ๐š shows all the ignored files, which can help you check whatโ€™s being skipped.

5๏ธโƒฃ ๐—–๐—ผ๐—บ๐—บ๐—ถ๐˜๐—ถ๐—ป๐—ด: Process of saving changes to your local repository, capturing a snapshot of your project's current state. By providing -๐š– (commit message) we are naming those changes that later we could easily understand what was done.

git commit -m "Created repo with multiple recipe files"

** You can use --๐š๐š’๐šก๐šž๐š™ with git commit to mark a fix for a previous commit, then combine them with git rebase --๐šŠ๐šž๐š๐š˜๐šœ๐šš๐šž๐šŠ๐šœ๐š‘ to streamline your commit history.

Now you know how to work locally with Git!

Blog image

This article is part of our Best Practices series. Check out our other articles.