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
Solutions Architect at Corgineering.com
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!
This article is part of our Best Practices series. Check out our other articles.