


Note that if you create or checkout master locally, Git typically would create origin/master as the default tracking branch behind the scenes. So, keeping in mind that origin/master is the actual branch which tracks the true remote master branch, we can tell Git to use origin/master as the tracking branch via: # from local master branch
Origin/master | local tracking branch for master which mirrors the remote version The easiest way to set an upstream branch is to use the '-set-upstream' option when pushing the branch to the remote repository for the first time: git push -set-upstream origin
Origin master | the master branch on the remote (as in the git pull command) Here is a brief summary: master | the master branch (either local or remote) Then, it does a merge into your local master branch using origin/master. The first step, git fetch origin, updates the local tracking branch origin/master with the latest changes, such that it mirrors the true master branch on the remote. Whenever you sync with the remote master branch, locally you are actually using origin/master.ĭoing git pull origin master is actually identical to this (assuming you are using the merge strategy by default): git fetch origin It exists mainly to serve as a proxy for the true remote master branch. This is a local branch, which exists on your local repo. Now, for the confusion, there is a third branch called origin/master. Similarly, there is also a branch called master which exists on the remote. The local branch master, which exists only in your local Git repo, is in what you do most of your actual development work. And you should have confusion, because it's confusing. You seem to have some confusion about references in the basic Git commands. Here is how it will look on your prompt once you've configured it: nick-macbook-air:~/dev/projects/stash$Īnd this is what you'll need to add to your. Wouldn't it be nice if you could see this information at your faithful command prompt? I thought so too so I started tapping with my bash chopsticks and cooked it up. Tip of the day: Ahead/Behind numbers in the promptĪfter a fetch, git status shows you how many commits you are ahead or behind of the synced remote branch. Rewriting history of shared repositories and branches is something you should NEVER do. Note: You should do this only when working with your own fork. We can shorten this if the remote’s branch name is the same as what it is locally. Personally I prefer to keep the history as clean as possible and go for option three, but different teams have different workflows. Example git push -u origin master:master. You have a few options: git push -f origin feature-x
Set upstream origin master git update#
Git checkout -b feature-x #some work and some commits happen #some time passes git fetch upstream git rebase upstream/main Publish with git forkĪfter the above steps, publish your work in your remote fork with a simple push: git push origin feature-xĪ slight problem arises if you have to update your remote branch feature-x after you've published it, because of some feedback from the upstream maintainers. In a standard setup, you generally have an origin and an upstream remote - the latter being the gatekeeper of the project or the source of truth to which you wish to contribute.įirst, verify that you have already setup a remote for the upstream repository, and hopefully an origin too:
git push -uLet me start by detailing a common setup and the most basic workflow to interact with upstream repositories. If you have no remote repos set up, you can set one up by doing the following, and then doing git push -u remote branch to set the default upstream location. Git upstream: Keep up-to-date and contribute In this blog, I’ll introduce you to the basics, the gotchas, and even leave you with a cool tip to get you ahead of the curve. To make sure all contributors are drawing from the same place, you’ll need to know some principles of how git forking interacts with git upstream. But if you’re not sending those changes back upstream-which means sending it back to the parent repository-you’re at risk for losing track of them, which can cause divergent lines in your repository. Forking projects to make your own changes lets you easily integrate your own contributions.
