Category Archives: Git

Git remove remote branch from repo via CLI

Quick shot: To remove a remote branch on your git repo:

git push [remote-name] --delete [branch-name]

Example

dkreling@dkreling:~/RobotFramework|devel ✔ ⟫ git branch -r
origin/devel
origin/master
origin/test

dkreling@dkreling:~/RobotFramework|devel ✔ ⟫ git push origin --delete teste [8:46:33]
remote: Updating references: 100% (1/1)
To ssh://dkreling@:/RobotFramework.git
 - [deleted] test

Cheers!

Advertisements

Selecting remote repository on git

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]

For example:

git_st_remote

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.

Cheers!

Reference: https://stackoverflow.com/questions/23455842/how-can-i-make-git-status-check-two-different-remotes

Git: two awesome quick commands

Find branches the commit is on

git branch --contains <commit #>

Sample output:

Screen Shot 2017-10-17 at 10.18.41 PM10-17-17

fetch_weather, implement_axios and master all have the commit # 3dea5b6

Ref.: https://stackoverflow.com/questions/2706797/finding-what-branch-a-git-commit-came-from

Show all branches with unmerged commits to <branch>

git branch -a --no-merged <branch>

Sample output:

Screen Shot 2017-10-17 at 10.22.39 PM10-17-17

remotes/origin/error_handler has not yet been merged into master

Ref.: https://stackoverflow.com/questions/3600728/git-list-all-unmerged-changes-in-git

Happy git work!

Cheers!

Git history (log) of a line

This is the first answer of this question on Stack Overflow, about how to see the history of a line of code on git.

Since git 1.8.4, there is a more direct way to answer your question.

Assuming that line 110 is the line saying var identifier = "SOME_IDENTIFIER";, then do this:

git log -L110,110:/lib/client.js

This will return every commit which touched that line of code.

[Git Documentation (see the “-L” command line paramenter)]

 

Cheers!

Git: find what commit inserted such file

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

That’s it.

Reference: https://stackoverflow.com/questions/11533199/find-commit-where-file-was-added