Therefore, I'm using the following alias in my. Not only it is a pain to type, but more importantly, it's quite error-prone! It's easy to make a mistake when typing the branch name, and the new remote branch won't have the same name as your local branch! In most cases, really, you want the upstream repository to be origin, and the upstream branch to have the same name as your local branch. However, I hate that we have to explicitly write git push -u origin foo. Personally, I do like the need to be explicit with git push -u when creating the remote branch: it's a pretty significant operation, sharing a whole new branch to the world. Git commit -m "Bar" # Create local commit Git push -u origin foo # Create and track remote branch, and push commit Git commit -m "Foo" # Create local commit Here is a typical scenario: git checkout -b foo # Create local branch This is only necessary for the first push on the branch. The remote repository doesn't yet have the new branch, so we need to tell git to create and track the remote branch before pushing the commit. It fetches and merges changes from the remote server to your working directory. Typically, the need for -u (shorthand for -set-upstream) is when we have just created a new local branch and commit, and we want to push it upstream. git push -u origin master git push -set-upstream origin master. Push-u = !git push -u origin $(git symbolic-ref -short HEAD) If you actually like to be explicit and use the -u option when necessary,īut just don't want to type the whole: git push -u origin foo Git push -u origin $(git symbolic-ref -short HEAD) || Sc0ttyD proposes in the comments the following alias: alias gpu='] & git push -u origin $(git symbolic-ref -short HEAD) || git push' So building up from mechanicalfish's answer, you can define an alias, with the right double quotes ( ") escaped ( \"): git config alias.pu "!] & git push -u || git push" There is a user preference configuration variable " fault" to change this. We will use the " simple" semantics that pushes the current branch to the branch with the same name, only when the current branch is set to integrate with that remote branch. When " git push " does not say what to push, we have used the traditional "matching" semantics so far (all your branches were sent to the remote as long as there already are branches of the same name over there). Setting an upstream branch is viewed as a voluntary step, not an hidden automated one Workflows most likely to benefit from this option are ' simple' central workflows where all branches are expected to have the same name on the remote.Ģ013: Note: the fact that the new default push policy " simple" relies on a branch having an upstream one means that: It is useful if by default you want new branches to be pushed to the default remote (like the behavior of ' fault=current') and you also want the upstream tracking to be set. This option takes effect with fault options ' simple', ' upstream', and ' current'. Upstream tracking exists for the current branch If set to " true" assume -set-upstream on default push when no Or use the mouse if you can avoid it.2022: Git 2.37 proposes: git config -global toSetupRemote true Git branch -set-upstream-to="origin/$upstream" "$current" Our entire function looks like this: # git branch -set-upstream-to Otherwise, we’ll use the name of the current branch: local upstreamĪll that remains is to run the git command. If we’re passed a parameter, we’ll use that for the name of the upstream branch. We’ll set the result to a local variable called “current”: local currentĬurrent="$(git rev-parse -abbrev-ref HEAD)" I was going to name this function “gsu” but I have that aliased to git submodule update.įor this function, we must retrieve the name of the current branch. If you haven’t deciphered it yet, “gsut” stands for Git Set Upstream To.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |