Category Archives: Git

If you are unable to connect to git server over https

NOTE: Make sure you know/trust the server you are communicating with in the first place

Sometimes, git servers can have issues with TLS or other secure handshaking procedures. This is often due to connecting from an older linux/ubuntu box. If you are truly desperate and don’t have time to fix the SSL/TLS properly, here is a very quick fix:

export GIT_SSL_NO_VERIFY=1

Then run your normal git fetch or git push command.

Setting your git username and email address

Single Repo

If you need to quickly set the user and email address for a single git repo, you can do this:


git config user.email john.doe@example.com
git config user.name "John Doe"

If you want to modify the .git/config file directly, you can add in this block:


[user]
name = John Doe
email = john.doe@example.com

All Repos


git config --global user.email john.doe@example.com
git config --global user.name "John Doe"

On Ubuntu 13+ and higher, /etc/bash_completion.d/git is now git-prompt

In this previous post I wrote about how to get some git branch information into your shell. That was written back when Ubuntu 12 LTS was the standard.

I recently upgraded a box to Ubuntu 16 LTS, and this information went away. 🙁

I discovered via trial and error, that the call that’s needed in .bashrc is now:

## To show you what branch you are in as you move around git repos
##
if [ -f /etc/bash_completion.d/git-prompt ]; then
. /etc/bash_completion.d/git-prompt
PS1='\[\u@\h \e[33m\]\w\[\e[0m\] $(__git_ps1 " (%s)")\n\$ '
fi


/etc/bash_completion.d/git is now: /etc/bash_completion.d/git-prompt

Fetch a remote branch that doesn’t exist locally using git

Say you are working on not your normal computer and are working on a branch that isn’t quite ready to get merged with the official git repo for the codebase. Here’s what you can do:

[bash]
git push SOME_OTHER_ORIGIN branch_name –tags –set-upstream
[/bash]

Then, when you get back to the computer you normally work on, you can do this:

[bash]
git fetch SOME_OTHER_ORIGIN

git checkout -b branch_name
# which will switch you to that branch

$ git fetch SOME_OTHER_ORIGIN branch_name
Password for ‘https://you@git.place’:
From https://git.place/….
* branch branch_name -> FETCH_HEAD

# Check this is what you want:
$ git log ..FETCH_HEAD

# if it is, then
$ git merge –no-ff FETCH_HEAD | more
[/bash]

NOTE: You might need to hide some local files that get gotten in the 1st place.

Git – automagically add modified files and rm deleted files

Sometimes a script will upgrade/add/modify/delete a large swath of files (possibly due to an upgrade-type script). If you are lazy, then you’ll want a script to help you commit those files. Here’s what I’ve come up with:

To perform a git add to all modified files:
[bash]
for file in `git status | grep modified | cut -d ":" -f 2`; do git add $file; done
[/bash]

To perform a git rm to all modified files:
[bash]
for file in `git status | grep deleted | cut -d ":" -f 2`; do git rm $file; done
[/bash]