Quick shot: To remove a remote branch on your git repo:
git push [remote-name] --delete [branch-name]
dkreling@dkreling:~/RobotFramework|devel ✔ ⟫ git branch -r
dkreling@dkreling:~/RobotFramework|devel ✔ ⟫ git push origin --delete teste [8:46:33]
remote: Updating references: 100% (1/1)
- [deleted] test
I recently started to work with two remote repositories on git, and then faced a probably common scenario: check the state of each repository (say ‘origin‘ and ‘vertiv‘).
A 20 minute search provided me the best solution:
$ git branch -u [remote-repo]/[branch]
In this case, origin/master is ahead of vertiv/master by 2 commits, and my local is sync’ed with vertiv/master.
The docs read:
-u <upstream>, –set-upstream-to=<upstream>
Set up <branchname>’s tracking information so <upstream> is considered <branchname>’s upstream branch. If no <branchname> is
specified, then it defaults to the current branch.
To add part of the changes of a file, or in other words, select what hunks you want to commit in a file, just issue:
git add --patch <filename>
This will prompt you to select which hunks in your file you want to stage.
As of the date of this post, this answer had 2557 upvotes on stackoverflow.
Find branches the commit is on
git branch --contains <commit #>
fetch_weather, implement_axios and master all have the commit # 3dea5b6
Show all branches with unmerged commits to <branch>
git branch -a --no-merged <branch>
remotes/origin/error_handler has not yet been merged into master
Happy git work!
I was in need of finding the commit that added a specific file in my project and “I got lucky” on Google:
Say we need the commit that introduced foo.js in the project, the command would be:
$ git log --diff-filter=A -- foo.js
And a super nice alias would be:
$ git config --global alias.whatadded 'log --diff-filter=A --'
and to use it:
$ git whatadded filename
To create a remote branch:
$ git checkout -b <branch-name>
$ git push -u origin <branch-name>
To delete a remote branch:
$ git push origin --delete <branch-name>
$ git branch -d <branch-name>
If there are unmerged changes which you are confident of deleting:
$ git branch -D <branch-name>
And that is all.