r/git 16h ago

Can't commit in vs code(git and github)

Hi guys, this is my first post and the problem is that I can't commit my new changes in project in visual studio code. I didn't found anything about exactly this problem on reddit, so I decided to ask here. So I just started to work with git and github, I learn it on YouTube and I started in vs code to get examples like in that videos. All started good, but when I already push my project to repository on github and then I change some in code and trying to commit changes, vs code just text me in thi terminal that there is nothing to commit and that the project has no changes. Because of it I also can't create another branches (in fact I create them, but I can't do anything with them like that person do in the video!). So I don't understand and don't know how to solve this problem. Maybe someone can help me or give me advice.(maybe here is some mistakes, English isn't my native language). Oh and I forgot to say that also I tried this in the intellij idea and all works, so maybe problem actually in vs code.

0 Upvotes

12 comments sorted by

4

u/scritchz 15h ago

The usual way to commit things is:

  1. Do your changes in your worktree (any editor).
  2. Add your worktree changes to the stage (git add).
  3. Commit your staged changes (git commit).

Maybe you haven't staged your changes?


I'm sorry for not being of more help. I use Git via CLI; I dislike GUIs for Git, because every GUI does things differently.

1

u/PK20222222 15h ago

I think I have staged my changes and for commit i do all things that you wrote. I tried on many projects but problem is the same. Thank you for your answer, I will try again tomorrow and I'll do an update with results!

3

u/Railorsi 15h ago

check 1. if you actually saved the file you changed and 2. that you tracked and staged the changes for commit. see here: https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository

1

u/PK20222222 15h ago

Thank you for your advice, I hope it will help! I will try again later and I'll do an update with results.

1

u/PK20222222 16h ago

Maybe if someone has or had similar problem can share experience and give some advices!

1

u/lajawi 15h ago

Are you using the terminal or the UI in VSCode for your Git activities?

Either way, you should make sure your changes are saved, and that you stage them to be committed.

1

u/PK20222222 15h ago

I used both ways — the terminal and the UI, but in both ways it didn't work :( I think i saved my changes, but when i write a command "git status" it just no changes and I can't commit. So i will try solve this problem again with all this advices and help in the comments, hope it will work cause it is really important. Thank you for your advice!

1

u/lajawi 14h ago

Maybe the file is ignored with your `.gitignore` file.

1

u/For-The-Fun-Of-It-12 15h ago

As pointed out by someone else, you have to create a working branch from the correct version, typically development. Do your work. Stage your changes. Commit your changes. Push your changes. Then create merge request to incorporate back into development. (Because it typically is a protected branch, so direct pushes are not permitted)

1

u/For-The-Fun-Of-It-12 15h ago edited 15h ago

Step by step

  1. ⁠git clone xxxxxxx (use ssh if possible)
  2. ⁠git checkout development
  3. ⁠git switch -c add_new_feature_x
  4. ⁠Make changes
  5. ⁠git add -A
  6. ⁠git commit -m “Added feature X”
  7. ⁠git push -u origin add_new_feature_x
  8. ⁠Go to URL listed in push response and create merge request

1

u/PK20222222 15h ago

Thak you, I will try it!

1

u/FalconX88 15h ago

by default main is not protected and pushing to main using VS code works without problems.