Git: Find the most recent common ancestor of two branches
You are looking for git merge-base. Usage: $ git merge-base branch2 branch3 050dc022f3a65bdc78d97e2b1ac9b595a924c3f2
You are looking for git merge-base. Usage: $ git merge-base branch2 branch3 050dc022f3a65bdc78d97e2b1ac9b595a924c3f2
If you hadn’t made any commit yet, only (1: branch) and (3: checkout) would be enough. Or, in one command: git checkout -b newBranch With Git 2.23+ (Q3 2019), the new command git switch would create the branch in one line (with the same kind of reset –hard, so beware of its effect): # First, … Read more
There are a few ways to accomplish that: Change your local branch and then push your changes Push the branch to remote with the new name while keeping the original name locally Renaming local and remote # Rename the local branch to the new name git branch -m <old_name> <new_name> # Delete the old branch … Read more
Run this from the branch where you want the file to end up: git checkout otherbranch myfile.txt General formulas: git checkout <commit_hash> <relative_path_to_file_or_dir> git checkout <remote_name>/<branch_name> <file_or_dir> Some notes (from comments): Using the commit hash, you can pull files from any commit This works for files and directories Overwrites the file myfile.txt and mydir Wildcards … Read more
How do we merge the master branch into the feature branch? Easy: git checkout feature1 git merge master There is no point in forcing a fast forward merge here, as it cannot be done. You committed both into the feature branch and the master branch. Fast forward is impossible now. Have a look at GitFlow. … Read more
Yes, you should be able to do git reflog –no-abbrev and find the SHA1 for the commit at the tip of your deleted branch, then just git checkout [sha]. And once you’re at that commit, you can just git checkout -b [branchname] to recreate the branch from there. Credit to @Cascabel for this condensed/one-liner version … Read more
You can control the default behavior by setting push.default in your git config. From the git-config(1) documentation: push.default Defines the action git push should take if no refspec is given on the command line, no refspec is configured in the remote, and no refspec is implied by any of the options given on the command … Read more
If you like the method in the link you’ve posted, have a look at Git Flow. It’s a set of scripts he created for that workflow. But to answer your question: $ git checkout -b myFeature dev Creates MyFeature branch off dev. Do your work and then $ git commit -am “Your message” Now merge … Read more
A shortcut, which doesn’t depend on remembering the syntax for git branch –set-upstream 1 is to do: git push -u origin my_branch … the first time that you push that branch. Or, to push to the current branch from a branch of the same name (handy for an alias): git push -u origin HEAD You … Read more
git checkout master # first get back to master git checkout experiment — app.js # then copy the version of app.js # from branch “experiment” See also git how to undo changes of one file? Update August 2019, Git 2.23 With the new git switch and git restore commands, that would be: git switch master … Read more