TGViewer
Бессонный кодер Бессонный кодер @sleeplesscode · 4.24K subscribers
Post #342 19.1K
К удивлению, заметил, что некоторые знакомые кодеры не знают, как пользоваться Git. Давайте вместе разберёмся!

Всё начинается с репозитория. Чтобы создать наш первый репозиторий, зайдите в корень вашего проекта и выполните команду init:
$ ls
.gradle .idea build.gradle gradle gradle.properties LICENSE run settings.gradle src
$ git init
Initialized empty Git repository in /tmp/repo/.git/


В каждом проекте есть файлы, которые нельзя или не хочется сохранять в истории и публиковать. Чтобы Git не трогал их, используется файл .gitignore. В нашем случае это .gradle, .idea и run:
$ echo '.gradle' >> .gitignore
$ echo '.idea' >> .gitignore
$ echo 'run' >> .gitignore


Теперь нужно сообщить Git, какие именно файлы добавить в индекс для последующего коммита. Для этого используется команда add. Она работает как с отдельными файлами, так и с целыми папками:
$ git add build.gradle
warning: LF will be replaced by CRLF in build.gradle.
The file will have its original line endings in your working directory
$ git add gradle
warning: LF will be replaced by CRLF in gradle/wrapper/gradle-wrapper.properties.
The file will have its original line endings in your working directory


Если вы хотите добавлять файлы более интерактивно, используйте add -i:
$ git add -i
staged unstaged path
1: +184/-0 nothing build.gradle
2: +1/-0 nothing gradle/wrapper/gradle-wrapper.properties

*** Commands ***
1: status 2: update 3: revert 4: add untracked
5: patch 6: diff 7: quit 8: help
What now>


Чтобы добавить в индекс все файлы, используйте add -A:
$ git add -A
warning: LF will be replaced by CRLF in .gitignore.
The file will have its original line endings in your working directory
[...]
warning: LF will be replaced by CRLF in src/main/resources/pack.mcmeta.
The file will have its original line endings in your working directory


Как проверить текущий статус? Используйте git status:
$ git status
On branch master

No commits yet

Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: .gitignore
[...]
new file: src/main/resources/pack.mcmeta


Теперь можно зафиксировать изменения с помощью commit:
$ git commit -m "First commit"
.git/hooks/post-commit: 8: git-stats: not found
[master (root-commit) 75e8167] First commit
26 files changed, 747 insertions(+)
create mode 100644 .gitignore
[...]
create mode 100755 src/main/resources/pack.mcmeta


Уже хочется поделиться, но сначала нужно указать, где будет храниться репозиторий. Для этого используется команда remote:
$ git remote add origin ssh://git@git.redguy.ru:2233/RedGuy/test.git  


Теперь мы готовы делиться! Для первой отправки изменений используйте push с указанием upstream. В дальнейшем можно использовать просто push:
$ git push --set-upstream origin master
Enumerating objects: 54, done.
Counting objects: 100% (54/54), done.
Delta compression using up to 12 threads
Compressing objects: 100% (38/38), done.
Writing objects: 100% (54/54), 14.64 KiB | 4.88 MiB/s, done.
Total 54 (delta 1), reused 0 (delta 0), pack-reused 0
remote: . Processing 1 references
remote: Processed 1 references in total
To ssh://git.redguy.ru:2233/RedGuy/test.git
* [new branch] master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.


Ну и остаётся только получить изменения от других людей с помощью pull:
$ git pull
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 292 bytes | 292.00 KiB/s, done.
From ssh://git.redguy.ru:2233/RedGuy/test
75e8167..2a51439 master -> origin/master
Updating 75e8167..2a51439
Fast-forward
README.md | 1 +
1 file changed, 1 insertion(+)
create mode 100644 README.md


Это краткое боевое руководство. Если хотите, можем более подробно разобраться с понятиями и сложными ситуациями.

#tech
  • 👍 246
  • 🤯 51
  • ❤ 34
  • 🔥 11
  • 🤩 7
  • ❤‍🔥 6
  • 🤡 6
  • 💯 5
  • 💋 1
  • 👻 1
  • 🎄 1
More from @sleeplesscode
  1. Oct 5, 2026Post #923
  2. Oct 1, 2026Post #914
  3. Sep 18, 2026Post #913
  4. Sep 17, 2026Post #912
  5. Sep 15, 2026Post #911
  6. Sep 14, 2026Post #909
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →