How to use git to send your changes to the server, specifically how to push a commit in git? Let's examine the entire process step by step:
-
Make the necessary changes in your project files. Then check these files with the command:
git status -
Add all changed files to the staging area:
git add .Or add files individually:
git add addresswhere
addressshould be replaced with the full path to the file. -
Verify that the files have been staged (they should now appear in a different color):
git status -
Commit from the staging area to your local repository. Replace
commit messagewith a short description of what the commit contains:git commit -m "commit message" -
To undo or uncommit a commit:
git reset --soft HEAD~1OR
git reset --soft HEAD^The above command reverses the commit itself (it undoes the commit) while leaving all files in the same state they were in before the
git commit -m "commit message"command. -
Push the commit to the server:
git push origin HEAD:refs/for/main // or 'stage' if you use 'stage' instead of 'main'If you are pushing to GitHub, for the first push you need to link your local branch to the remote branch, so use:
git push -u origin feature/name-of-branchFor subsequent commits / pushes to GitHub, use the command without
-u:git push origin feature/name-of-branch
That's it, now commit has been sent to the server.