Git push branch from one remote to another?

I’ve found this one: git push rorg ‘refs/remotes/korg/*:refs/heads/*’ And it pushed all my remote branches from korg to rorg (even without local copies of the branches). See the output below: Counting objects: 293, done. Delta compression using up to 4 threads. Compressing objects: 100% (67/67), done. Writing objects: 100% (176/176), 48.32 KiB, done. Total 176 … Read more

Git: Merge a Remote branch locally

You can reference those remote tracking branches ~(listed with git branch -r) with the name of their remote. You need to fetch the remote branch: git fetch origin aRemoteBranch If you want to merge one of those remote branches on your local branch: git checkout aLocalBranch git merge origin/aRemoteBranch Note 1: For a large repo … Read more

Create Git branch with current changes

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

Git Diff of same files in two directories always result in “renamed”

There are multiple questions here, whose answers intertwine. Let’s start with rename and copy detection, then move on to branches. Rename detection However because the diff takes into account the file path as part of the file name, files with the same name, in the two different directories, result in a diff output with the … Read more

Git: track branch in submodule but commit in other submodule (possibly nested)

Update 2020: The OP BartBog reports in the comments: The current (2016) answer does not work that well (anymore?) with subsubmodules since $top/.gitmodules does not contain the branch info of the subsub (and subsubsub modules) New solution: export top=$(pwd) git submodule foreach ‘b=$(git config -f ${top}/.gitmodules submodule.${path}.branch); \ case “${b}” in \ “”) git checkout … Read more

git how to find commit hash where branch originated from

You can use git reflog show –no-abbrev <branch name>. It will output all changes made to the branch, including it’s creation, for example (I created branch xxx from master branch): bdbf21b087de5aa2e78a7d793e035d8bd9ec9629 xxx@{0}: branch: Created from master Note that this is not very reliable as reflog records can expire (90 days by default), and it seems … Read more

Git undo local branch delete

You can use git reflog to find the SHA1 of the last commit of the branch. From that point, you can recreate a branch using git branch branchName <sha1> Edit: As @seagullJS says, the branch -D command tells you the sha1, so if you haven’t closed the terminal yet it becomes real easy. For example … Read more