1

I see a lot of posts about this and I know the general answer, executing this from my fork's local repo:

git remote add upstream https://github.com/abcd/efgh.git
git fetch upstream
git merge upstream/master
(resolve merge conflicts)
git commit -m "my message"
git push

But I have a couple of questions beyong the general case.

  1. When I do the git push, why do i not have to specify with remote I am pushing to? or do I?
  2. Also, how can i get a particular commit id from upstream instead of the latest commit which is what I would get when I do fetch upstream?
ssn
  • 2,311
  • 4
  • 21
  • 24
  • 1. You can choose to mention the remote you are pushing to. If not mentioned it uses the tracked remote for that local branch. – leoOrion Jul 08 '20 at 18:28
  • 2. https://stackoverflow.com/questions/14872486/retrieve-specific-commit-from-a-remote-git-repository – leoOrion Jul 08 '20 at 18:28
  • 1. About bare `git push`: see [`git config push.default`](https://git-scm.com/docs/git-config#Documentation/git-config.txt-pushdefault). Default value is `simple`. – phd Jul 08 '20 at 18:34

2 Answers2

0
  1. git push without any further arguments will use the branches' upstream to determine where to push. If you're on a branch, then git status will show you current upstream for this branch (if any).

    You can git branch --unset-upstream or git --set-upstream=newupstream/example

    If you want to push your currently checked-out branch to a specific place, e.g. upstream you can just do git push upstream master

  2. Specify the commit you want to fetch: e.g. git fetch upstream 61586219a7450af5a72f857db62d9a89ad9cc38f

    The fetched commit can be accessed in git commands using FETCH_HEAD. E.g. git log FETCH_HEAD.

Note: Not all repositories allow fetching arbitrary commits. E.g. they may only permit fetching named branches and pull requests (github).

Jay
  • 1,927
  • 8
  • 15
0

What I did was:

git remote add upstream https://github.com/abcd/efgh.git
git fetch upstream
git checkout 1q2w3e4r5t -b giveItABranchName
git checkout main
git merge giveItABranchName
(resolve merge conflicts)
git commit -m "my message"
git push
ssn
  • 2,311
  • 4
  • 21
  • 24