-5

I recently used this command

 git push

I want to know what are the differences when I use these commands

git push origin master
git push -u
git push -f
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Dulanga Heshan
  • 1,335
  • 1
  • 19
  • 36
  • 2
    So read the docs: https://git-scm.com/docs/git-push – jonrsharpe Jul 14 '18 at 17:35
  • 2
    `git push --help` and read – Cory Kramer Jul 14 '18 at 17:38
  • 4
    Sadly you're gonna get downvoted because you're straight up asking a question that can be answered by reading the docs. If you're still not sure provide an example poiting out what's not clear so people can help you. – oxfist Jul 14 '18 at 20:57
  • 2
    because i'm new to open source and git i couldn't understand clearly some terms and commands by reading docs that's way i asked here – Dulanga Heshan Jul 14 '18 at 21:09
  • https://stackoverflow.com/questions/5697750/what-exactly-does-the-u-do-git-push-u-origin-master-vs-git-push-origin-ma – phd Jul 15 '18 at 12:36
  • https://stackoverflow.com/questions/12462481/what-is-the-difference-between-git-push-origin-and-git-push-origin-master – phd Jul 15 '18 at 12:36
  • As Roman Mars says “always read the plaque”. I personally go man page -> tldr (npm tool) -> googling tutorials -> stack overflow. – evolutionxbox Jul 15 '18 at 14:20

3 Answers3

3

The git push command allows you to send (or push) the commits from your local branch in your local Git repository to the remote repository.enter link description here

The most common use of git push is to push your local changes to your public upstream repository. Assuming that the upstream is a remote named “origin” (the default remote name if your repository is a clone) and the branch to be updated to/from is named “master” (the default branch name), this is done with:

git push origin master

enter link description here

2
git push origin master

Find a ref that matches master in the source repository (most likely, it would find refs/heads/master), and update the same ref (e.g. refs/heads/master) in origin repository with it. If master did not exist remotely, it would be created.

-u --set-upstream For every branch that is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull and other commands. For more information, see branch..merge in git-config.

-f --force Usually, the command refuses to update a remote ref that is not an ancestor of the local ref used to overwrite it. Also, when --force-with-lease option is used, the command refuses to update a remote ref whose current value does not match what is

Link to documentation

Community
  • 1
  • 1
Maxim Kasyanov
  • 938
  • 5
  • 14
2

git push assumes that you already have a remote repository defined for that branch. In this case, the default remote origin is used. git push origin master indicates that you are pushing to a specific remote, in this case, origin . This would only matter if you created multiple remote repositories in your code base.

Chanaka
  • 760
  • 1
  • 10
  • 21