'git branch' does not show the branches names - github

I am using git on ubuntu.
git branch does not show the branches' names. I tried cloning different repositories, but again git branch does not show the branches' names.
I have also created a new repository and it is the same.
Example:
>git clone https://github.com/uber/pyro.git
Cloning into 'pyro'...
remote: Counting objects: 13342, done.
remote: Compressing objects: 100% (23/23), done.
remote: Total 13342 (delta 8), reused 0 (delta 0), pack-reused 13319
Receiving objects: 100% (13342/13342), 55.85 MiB | 5.34 MiB/s, done.
Resolving deltas: 100% (9814/9814), done.
>ls
pyro
>cd pyro
>git branch -a
>git branch -r
>git branch
>git status
On branch dev
Your branch is up to date with 'origin/dev'.
Adding another branch:
>git checkout -b branch1
Switched to a new branch 'branch1'
>git branch
>
I have also committed one time. and it is the same.
>GIT_TRACE=1 git branch
15:39:13.295464 git.c:344 trace: built-in: git branch
15:39:13.296121 run-command.c:640 trace: run_command: unset
GIT_PAGER_IN_USE; LESS=FRX LV=-c pager
>git --version
git version 2.17.1
>
>env -i git branch
WARNING: terminal is not fully functional
* devress RETURN)
>
I have tested the same commands on another laptop and it works. (I have also uninstalled git and reinstalled it. It doesn't help)
Any idea how to fix it?

This is not a complete answer, but based on a lengthy chat discussion, it looks like some kind of interaction with the pager.
The user's environment includes these variables (among others):
LESSOPEN='| /usr/bin/lesspipe %s'
LESSCLOSE='/usr/bin/lesspipe %s %s'
Those are the default settings on Ubuntu, so that shouldn't be causing a problem.
git branch produces no output.
GIT_PAGER=/bin/cat git branch produces the correct output.
I haven't yet figured out why the pager should be causing this problem, but since changing GIT_PAGER to /bin/cat is a workaround, that must be what the issue is.

Show local branches:
git branch
Since you are cloning from remote/origin branches, it will not displaying using git branch. you need to at least visit that branch by using git checkout. Review below git commands. I have created new branch hotfix-test and then used git branch
~/pyro (dev)
$ git checkout -b hotfix-test
Switched to a new branch 'hotfix-test'
~/pyro (hotfix-test)
$ git branch
dev
* hotfix-test
Checkout the current branch to existing other branch.
$ git checkout lax
Switched to a new branch 'lax'
Branch lax set up to track remote branch lax from origin.
~/pyro (lax)
$ git branch
dev
hotfix-test
* lax
Cloning steps and origin branches
~/desktop (master)
$ git clone https://github.com/uber/pyro.git
Cloning into 'pyro'...
remote: Counting objects: 13342, done.
remote: Compressing objects: 100% (23/23), done.
remote: Total 13342 (delta 8), reused 0 (delta 0), pack-reused 13319
Receiving objects: 100% (13342/13342), 55.85 MiB | 2.69 MiB/s, done.
Resolving deltas: 100% (9814/9814), done.
~/desktop (master)
$ cd pyro
desktop/pyro (dev)
$ git branch -a
* dev
remotes/origin/0.1.2-release
remotes/origin/0.2.0-release
remotes/origin/0.2.1-release
remotes/origin/HEAD -> origin/dev
remotes/origin/ast-char-rnn
remotes/origin/bnn-mnist
remotes/origin/causal-tutorial
remotes/origin/continuation-poutine
remotes/origin/continuation-with-indep
remotes/origin/cubo
remotes/origin/dev
remotes/origin/dice-elbo
remotes/origin/gh-pages
remotes/origin/glom-autoname
remotes/origin/hmc
remotes/origin/jit-integration-tests
remotes/origin/lax
remotes/origin/lax2
remotes/origin/maps-iei
remotes/origin/master
remotes/origin/mvn-sym
remotes/origin/mvncv
remotes/origin/nightmare-poutine
remotes/origin/nips-2017
remotes/origin/only-continuation-poutine
remotes/origin/only-parallel-enumeration
remotes/origin/paul-mh-12-1
remotes/origin/pcg
remotes/origin/pragmatics-example
remotes/origin/ps-semaphore
remotes/origin/pyro_GP
remotes/origin/recursion-scope
remotes/origin/regtest-1
remotes/origin/rejector-research
remotes/origin/revert-611-verlet-pr
remotes/origin/rsa-ccg-example
remotes/origin/sampling-hash
remotes/origin/snorkel-example
remotes/origin/trace-posterior-sample-fix
remotes/origin/tst
remotes/origin/vec-rand-module
~/desktop/pyro (dev)
$ git branch -r
origin/0.1.2-release
origin/0.2.0-release
origin/0.2.1-release
origin/HEAD -> origin/dev
origin/ast-char-rnn
origin/bnn-mnist
origin/causal-tutorial
origin/continuation-poutine
origin/continuation-with-indep
origin/cubo
origin/dev
origin/dice-elbo
origin/gh-pages
origin/glom-autoname
origin/hmc
origin/jit-integration-tests
origin/lax
origin/lax2
origin/maps-iei
origin/master
origin/mvn-sym
origin/mvncv
origin/nightmare-poutine
origin/nips-2017
origin/only-continuation-poutine
origin/only-parallel-enumeration
origin/paul-mh-12-1
origin/pcg
origin/pragmatics-example
origin/ps-semaphore
origin/pyro_GP
origin/recursion-scope
origin/regtest-1
origin/rejector-research
origin/revert-611-verlet-pr
origin/rsa-ccg-example
origin/sampling-hash
origin/snorkel-example
origin/trace-posterior-sample-fix
origin/tst
origin/vec-rand-module
See Also
Why is "git branch" silent in new repositories?

I have disabled the git pager for the git branch by using git config --global pager.branch false. Now I can get the git branch output. But we didn't figure out what is the pager problem. For the other commands like git diff, the same problem exists.

Related

How to patch remote source code locally in yocto project?

Sometimes, We meet a situation that remote source code fetched by a recipe need to be modified so that suit a specific machine.
How do we create a patch for remote source code locally? After that everytime we build the recipe (even clean it all) we can patch the remote source code automatically.
For example, I have a special machine with architecture A which is not common, so the remote source code need to be modified so that support architecture A.
Suppose there was a file called utils.h (which is code that we fetched by example.bb from remote git repository)
#if defined(__x86_64__) || \
defined(__mips__) || \
defined(__powerpc__) || defined(__ppc__) || defined(__ppc64__) \
#define SOME_FUNCTIONALITY 1
Apparently I need to add archtecture A support in the file.
#if defined(__x86_64__) || \
defined(__mips__) || \
defined(__powerpc__) || defined(__ppc__) || defined(__ppc64__) || \
defined(__A__) \
#define SOME_FUNCTIONALITY 1
But if we just modified like that, next time we execute
bitbake -c cleanall example
bitbake example
then we get a unchanged copies again(which means we have to modify it again).
How do we create a Add-architecture-A-support.patch locally so that we can patch the remote source code automatically?
This is a simple one from answers.
(Note: If there was no git in the source code directory, before modifying the source code, you need to create a git repository and commit all in the top directory of the source code.)
git init # create a git repository
git add .
git commit -m "First commit" # first commit
After change the utils.h as above, we can check the git status. It usually looks like that.
$ git status
HEAD detached from 87b933c420
Changes not staged for commit:
(use "git add <file>..." to update what will be comitted)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: ../../utils.h
...
no changes added to commit (use "git add" and/or "git commit -a")
Then we add and commit the change locally (usually we don't have the permission to push to upper stream).
$ git add utils.h
$ git commit -m "Patch test"
After that we can use git to create a patch for the recent commit.
$ git show >Add-architecture-A-support.patch
It will creat a patch in the current directory with contents looks like that
commit a79e523...
Author: 杨...
Date: ...
Patch test
diff --git a/somedir/utils.h b/somedir/utils.h
index 20bfd36c84..
--- a/somedir/utils.h
+++ b/somedir/utils.h
...
+ defined(__A__) \
...
Then we can move the patch to the local layer where the recipe stayed.
recipe-example
|-- example
| |-- Add-architecture-A-support.patch
|-- example.bb
And add the patch in example.bb with this.
SRC_URI += "\
file://Add-architecture-A-support.patch \
"
Work finished. (Also, if want to undo the local commit after creating the patch, you can use git reset HEAD^ utils.h. emmm, I think so, maybe there are some faults, just google it)

unable to delete git branch due to "renamed branch"

I've scoured several different posts but there doesn't appear to be any that match with this exact issue of an "apparent" branch renaming occurring but nothing seeming to line up.
Essentially, I've been trying to delete a remote branch off of an enterprise git version but I've been getting rejected and I was wondering if there was any additional steps I can try out?
here is the following CLI information:
| => git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/releases/v1.7.2_log4j2
(base)
| ~/Documents/<repo> # (user)
| => git push origin -d releases/v1.7.2_log4j2
To https://github.<company>.com/<org>/<repo>.git
! [remote rejected] releases/v1.7.2_log4j2 (branch releases/v1.7.2_log4j2 is being renamed)
error: failed to push some refs to 'https://github.<company>.com/<org>/<repo>.git'
My git version: 2.24.3 (Apple Git-128).
EDIT: there are no branch protection rules that apply to this branch and I have tried the command in the suggestions of git push -d origin releases<1.7.2_log4j2 with the same result
This looks like a github issue. There is a github-community thread where someone got the exact same message and it turned out to be a flag that was set within the github system that marked the branch as being renamed at the moment. They had to ask the github-support to clear that flag and then were able to delete the branch.
You seem to have your parameters backwards. Try
git push -d origin releases/v1.7.2_log4j2

How to push to own github gist with password, without TFA?

So, I've tried setting up a gist under my own username on github:
https://gist.github.com/sdaau/771e0ca9b9f1fa17464373266400386f
... and I'm trying to clone, edit and push to this gist. I do not have 2-factor authentication (2FA) enabled in Your Profile/Edit Profile/Security (github.com/settings/security).
I would like to clone this repo, so when I push, I authenticate with my GitHub password, and not with a personal access token; and also I would like to avoid creating public keys for SSH access.
This is what I can observe so far:
cd /tmp/
$ git clone https://sdaau#gist.github.com/771e0ca9b9f1fa17464373266400386f.git yet_another_git_tute_gist
Cloning into 'yet_another_git_tute_gist'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
Checking connectivity... done.
So, when cloning, even if I have my username specified in the HTTPS url, I'm not being asked for a password, the repository just gets cloned. This is an example of changes before push:
cd yet_another_git_tute_gist/
git config user.name sdaau
git config user.email sdaau#whatever
echo >> README.md # just add empty line
git add README.md
git commit -m 'testing'
# [master 0f958d5] testing
# 1 file changed, 1 insertion(+)
... and this is the push:
$ git push --all
Password for 'https://sdaau#gist.github.com':
remote: Invalid username or password.
fatal: Authentication failed for 'https://sdaau#gist.github.com/771e0ca9b9f1fa17464373266400386f.git/'
Would anyone know what am I doing wrong?
Oh well, after half an hour of re-cloning, changing and getting the push error, just as I was writing this question, eventually it succeeded:
$ git push --all
Password for 'https://sdaau#gist.github.com':
Counting objects: 5, done.
Writing objects: 100% (3/3), 246 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://sdaau#gist.github.com/771e0ca9b9f1fa17464373266400386f.git
b706450..0f958d5 master -> master
... so I'm guessing I wasn't typing my password right. Still, let's keep this Q/A online, as I didn't find an example exactly worded like this one (and had I found one, I would have probably tried a bit harder to enter the right password).
Note to self: remote: Gist does not support directories.

git svn interrupted, then i lost all the tags, how to fix it?

i am about to clone code from svn repo (on centos) using git svn clone -s svn://xxx, then it is interrupted for strange problems, the error message is as follows:
Following parent with do_switch
Successfully followed parent
Use of uninitialized value in concatenation (.) or string at /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi/SVN/Core.pm line 584.
Network connection closed unexpectedly: at /usr/libexec/git-core/git-svn line 2693
then i continue this clone process using
time git svn fetch -r HEAD
all the things seems goes well, and succeed to clone that svn repo at last:
W: -empty_dir: trunk/src/os/win32/ngx_gui.c
W: -empty_dir: trunk/src/os/win32/ngx_gui.h
W: -empty_dir: trunk/src/os/win32/ngx_gui_resources.h
W: -empty_dir: trunk/src/os/win32/ngx_shared.h
W: -empty_dir: trunk/src/os/win32/ngx_types.h
r4817 = 7b58fc00b5b8ebb0544053ecf63e53b28935f15b (refs/remotes/trunk)
Auto packing the repository for optimum performance. You may also
run "git gc" manually. See "git help gc" for more information.
Counting objects: 12449, done.
Compressing objects: 100% (12177/12177), done.
Writing objects: 100% (12449/12449), done.
Total 12449 (delta 9475), reused 0 (delta 0)
Checked out HEAD:
svn://svn.nginx.org/nginx/trunk r4817
real 0m9.630s
user 0m6.015s
sys 0m1.870s
the strange issue is that there is no tags in my local git repo which is cloned from svn repo:
[root#home nginx]# git branch
* master
[root#home nginx]# git tag // no tags at all:(
[root#home nginx]# svn ls svn://svn.nginx.org/nginx/branches | wc -l
7
[root#home nginx]# svn ls svn://svn.nginx.org/nginx/tags | wc -l
388
in fact there are 388 tags in the svn repo, so how to fix my local .git repo?
should i have to restart to git clone from the remote svn server?
i have tried many times, with the same problem:(
Basically git-svn doesn't support tags as Git tags. In order to convert SVN tags to Git tags you may use:
SubGit (+maybe svnsync if you have no access to the server with SVN repository)
git-svn + command for references update:
"git update-ref refs/tags/TAGNAME refs/remotes/tags/TAGNAME"
SmartGit, if you want some UI and not writing a script
But note: only the 1st and the 3rd solutions allow you to push tags to the server to be conerted to SVN tags. With git-svn you should use additional "git svn branch" command.

How to setup/debug github WebHook?

I have this local repo, I make changes and run:
git add .
git commit -m "message"
git push -u origin master
My github has two WebHooks set-up, one going to a http://requestb.in URL and another one going to a PHP executable script (755), in the same folder (accessible from outside).
The PHP script:
<?php echo `git pull origin master`;
// echo "works";
// echo `whoami` ?>
The commented test lines are working so this is my proof that the script path is OK and also the syntax.
However, after I push changes from local to github repo, I check files on the server but nothing happens, is obvious echo git pull origin master from my PHP script does nothing.
If I run this in a shell logged as a root (git pull origin master), the files are getting updated with the latest version from the repo.
Also, the second hook I have set-up, the one from requestb.in works as I can see the requests from github.
My folder on the server has the right permission, is accessible form the outside, I am desperate and I don't know how to get this working.
What is wrong, how can I make this working? How do I set-up the WebHook in the admin panel in github, or is it the PHP script, is there a permissions issue, what's wrong?! :O
Thank you.
Update after my 3 comments:
After dealing with it for couple more hours, I can clearly see that the WebHook doesn't really fire up the php file. If I run in shell logged as a root "php test.php" I get:
root#echo [/home/moove/public_html/dev/wert]# php hooh.php
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (1/1), done.
remote: Total 3 (delta 1), reused 3 (delta 1)
Unpacking objects: 100% (3/3), done.
From github.com:chrisdemetriad/wert
* branch master -> FETCH_HEAD
Updating 0c67b85..89e4fdf
Fast-forward
XXX.php | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
root#echo [/home/moove/public_html/dev/wert]#
Which is what I need and the files on the server get updated. But if I don't do it manually, the files do not get updated and this must be because of the php script. My latest version that works:
<?php echo `git pull origin master`;