DEV Community

Cover image for How(and why) to commit.
JustKooba
JustKooba

Posted on

How(and why) to commit.

Commiting is an important topic in web development. But a lot of beginners are curious: What should I commit? and how often should i commit? or how to commit?
The answer is simple. You should commit everything, every small chage you did - you commit.
But why?
Imagine you're working on a project 8 hours a day, you've just finished your work and then all your files got corrupted. You've lost all your work! But not if you commit everything - thats why.
To commit our work we use Git.

When should I start using git?
Most of developers say:

You should learn git after javascript

But in my opinion: You should start either after css or as you start learning js.

How do I get git?
it's easy! just download git on your pc from here.

How to use git?

If you want to start using git in your current project you have to use the command git init. after that your local git repository is active and running. The next step is to connect to a remote repository on Github, to accomplish that you firstly need to create a github repository and then connect to it. use the command git remote add origin [link to your repository].
Now your git repo is connected to your github repo.

How to commit?
Let's say you've just finished some changes. To commit them use the commands below:

git add .
git commit -m "[your commit message]"
git push -u origin
Enter fullscreen mode Exit fullscreen mode

note: if you get this error mesage(error: failed to push some refs to [repo]
hint: Updates were rejected because the remote contains work that you do
) after git push, use the command git push -f origin to forcefully push your work on the Github repo.

after that you can refresh your github and your files will be there!

Thank you for reading. Happy coding!

Top comments (0)