183

I'm using visual studio 2013, and I'm faced with 3 options for when I commit my C# code. I need an explanation of the differences between each of the options with regards to what happens to my local repo vs. the GitHub repo.

  • Option 1 says Commit
  • Option 2 says Commit and Push
  • Option 3 says Commit and Sync

I don't quite understand the difference between the last 2 options. When should I use Commit and Sync as opposed to Commit and Push?

Alfred Waligo
  • 2,809
  • 3
  • 18
  • 26

4 Answers4

275
  1. Commit will simply make record of your changes that you have made on your local machine. It will not mark the change in the remote repository.
  2. Commit and Push will do the above and push it to the remote repository. This means that any changes you have made will be saved to the remote repository as well.
  3. Commit and Sync does three things. First, it will commit. Second, it will perform a pull (grabs the updated information from the remote repo). Finally, it will push.

See more from Microsoft here

camiblanch
  • 3,866
  • 2
  • 19
  • 31
  • I really don't get the "Commit and Sync" First, it will commit. Second, it will perform a pull Finally, it will push. Why push required here when code changes are already committed to the remote repository(No changes to push). – Bhuwan Pandey Jun 04 '16 at 00:17
  • 7
    @BhuwanPandey Performing a "commit" doesn't include a "push". They are separate. Only a "push" will update your commit to the remote repository. See the image in the other answer to see that. The "commit" goes from index to local repository, while "push" finishes by going from the local repository to the remote repository – camiblanch Jun 08 '16 at 18:19
  • Can Sync operation cause conflicts when multiple users working simultaneously into the application? – Murali Dhar Darshan Feb 08 '19 at 10:32
  • 1
    I am using Visual Studio 2017, and the Commit and Sync command does not completely push your changes. I'm saying that because by performing a Sync my changes are shown in the history tab in Visual Studio, but at Github site it doesn`t appear. I had to perform a Push command after Commig and Sync, and then my changes appeared in Github site. – Fabiano Jun 16 '19 at 19:01
  • I think confusion comes from thinking Commit sends files to the remote repository. In fact Commit merely records your edits with the local repository. Without Push it never hits the server. – Alan Baljeu Jan 11 '20 at 21:44
  • 2
    @Fabiano Agreed. If I do Commit and then Sync, I am prompted to push to commit to the remote server. This would seem to be at odds with the answer here. – Robbie Dee Sep 18 '20 at 16:53
88

To add to camieblanch's answer. I found this helpful picture/post from tanascius (here). "Here is a nice picture from Oliver Steele, that explains the git model and the commands:" enter image description here

Alan Baljeu
  • 2,383
  • 4
  • 25
  • 40
A.sharif
  • 1,977
  • 1
  • 16
  • 27
  • 1
    But where is Sync in this picture? – Alan Baljeu Jan 11 '20 at 21:46
  • 3
    It doesn't exist in the picture. If you refer back to "camiblanch"'s answer. It's commit to your local repo, pull to sync(merge) the remote repo with your local repo and then it pushes the merged local repo to the remote repo. – A.sharif Jan 13 '20 at 15:02
4

In GitHub, the "commit" action saves your changes to the local repository, while the "push" action sends those changes to a remote repository. "Commit and push" combines these two actions into one, allowing you to save your changes locally and then push them to a remote repository with a single command.

"Commit and sync" is a similar concept, but it also pulls down any changes from the remote repository that have been made since your last commit. This allows you to keep your local repository up to date with the latest changes from other contributors.

Finally, "commit and create pull request" combines the commit and push actions with the creation of a new pull request. This allows you to propose your changes for review by other contributors to the project, and start a discussion about the changes you've made.

In summary, the differences between these options are:

"Commit": saves your changes to the local repository "Commit and push": saves your changes to the local repository and pushes them to the remote repository "Commit and sync": saves your changes to the local repository, pulls down any new changes from the remote repository, and merges them with your local repository "Commit and create pull request": saves your changes to the local repository, pushes them to the remote repository, and creates a new pull request for review.

Ali
  • 41
  • 1
3

Checkout on this. It will be helpfull for understand push, pull, commit and sync.

https://learn.sparkfun.com/tutorials/using-github-to-share-with-sparkfun/committing-pushing-and-pulling

hmlasnk
  • 1,160
  • 1
  • 14
  • 33