How to push a commit in git. Do git commit

How to push a commit in git. Do git commit

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:

  1. Make the necessary changes in your project files. Then check these files with the command:

    git status

  2. Add all changed files to the staging area:

    git add .

    Or add files individually:

    git add address

    where address should be replaced with the full path to the file.

  3. Verify that the files have been staged (they should now appear in a different color):

    git status

  4. Commit from the staging area to your local repository. Replace commit message with a short description of what the commit contains:

    git commit -m "commit message"

  5. To undo or uncommit a commit:

    git reset --soft HEAD~1

    OR

    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.

  6. 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-branch

    For 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.