I would like to solve a doubt regarding those commit
of git
Let's suppose the following example:
I have created a repository on GitHub , let's call it example . In git bash I have linked it to a directory on my pc to start working on that repository. Finally I create 1 branch called
main
(I would have at this point the main branch and the master branch ). And I start working on main ...
Main at this point has the same as master as it has been created now, and master has nothing. Therefore neither of the two branches have anything.
1st thing I do :
I create a file calledindex.php
. I do a git add index.php
to add the file and a git commit -m " mi primer commiteo en este branch"
to register the commit, finally I upload it with a git push origin main
. With this , the file already uploaded has a main branch.index.php
2nd thing I do:
I append to the index.php
un <h1>
and then commit . Then I add a <p>
and then commit . I have added two things but I have not pushed until this point I have 2 commits in the chamber , that is, in local but not in my remote repository.
Now, when I do the push to upload the commits , these commits ...
Question: Will the two commits be uploaded at once? If so, will these commits have the date of the moment I committed or the moment I pushed ?
In response to your question about whether commits would be uploaded all at once: Yes, you upload the entire branch.
Regarding the date. It is information from the commit, not from the push, so in github you will see the commit as of yesterday if you made the commit yesterday but you have pushed your branch today.
When you do a
git push
, git compares the commit at the head of the remote branch with the commit history of the local branch, until it finds it. Then push all commits that appear after that to the remote branch.If it couldn't find the latest remote commit on your local branch, it would throw an error and the push wouldn't be possible. This can happen if someone (another collaborator in the project) had made a
push
before you, since in that case the last commit that is in the remote is not you in local. To solve this problem you would have to do agit pull
to download those commits that someone else had added and that you did not have. That will cause a mix of your changes with those that come (as if you had merged your branch with the one that comes from the repository. From there you could already do apush
, which would upload your commits and the merge commit.The push does not affect the dates and authors of the commits, nor any other meta-information contained in the commits. Just copy those commits to another computer (in this case Github).