The output states our local branch is behind the remote branch and if we want to push our changes we can use the -f or force option. So if we were to run: git push origin head This creates the scenario where our local branch is behind the remote branch. If I run git log -oneline -decorate -all we'll see my local force-push branch is behind the register branch. Then I'll create a local force-push branch from master, by running: git checkout -b force-push master To simulate this, let's push the register branch to a new remote branch called force-push. For example, if someone else has pushed work to the same remote branch while you were working. There will be times when your local branch gets behind the remote branch. There's one last scenario to cover, which is force push. Or, said another way, we pushed nothing to a remote branch which removes it. This is a bit of syntactic sugar, but if we think about it we didn't specify a local branch name. So, to delete new-branch, we would run: git push origin :new–branchįrom the output we see that the branch was deleted and we also see it was removed on GitHub. The syntax is similar to the previous command except we don't pass a local branch name. You can also delete a remote branch with git push. I'll do so by running: git push origin register:new–branchįrom the output we see that new-branch was created and we also see it on GitHub. Let's demonstrate this by pushing our current local branch to a different remote branch named new-branch. You can do so by passing the remote branch name immediately after the local branch name, separated by a colon. Sometimes you may want to push your local branch to a remote branch with a different name. So while prefer being explicit by running git push origin HEAD, you can often simply run git push. We see from the output Git pushed our current branch to the origin remote. This will automatically set the tracking branch to the one I'm pushing too.įurthermore, if you don't specify a remote name, git push will use origin by default. So, we'll use the suggested command, or we could also use the -u option for git push. It provides a command we can run to set what's called the tracking branch. This command fails because Git can't match the local branch name with origin. Let's try this by just running: git push origin While it's nice to be consistent, we really haven't shortened the command.Įven if we don't pass the branch name to git push, Git will attempt to use the current branch.īy default, so long as this branch name matches a branch name on the remote, this will work. So, we can use HEAD as a way to keep the git push command consistent across different branches. We can demonstrate this by running git log -online -decorate to see that HEAD and our branch reference the same commit. If we think about our common use case, we're usually pushing the latest work on our branch.Īs we learned in Part 3, HEAD also references the top most commit on a branch. It be nice if we could just type the same command for each branch. If we have to pass git push the name of the branch, this means we'll need to type a different git push command for each branch. Let's take a closer look at these arguments to understand how we might be able to use some shorthands. In init: git push we covered the most common usage of git push by passing the remote name followed by the branch name. In this video we'll learn some short hands and additional scenarios for git push.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |