Archive

Archive for the ‘git’ Category

Joe – A .gitignore magician in your command line.

March 14, 2016 Leave a comment

http://karan.github.io/joe/

A .gitignore magician in your command line. Joe generates .gitignore files from the command line for you.

joe

sample

Categories: git, Interesting, python Tags: ,

Deleting a branch (locally and remotely)

January 13, 2016 1 comment

Problem:

I needed to delete a git branch but not lose the data on the branch. The desired outcome was to have a new branch that had the same details are the old branch and to empty out the old branch.

My existing state:

master # Empty
old_branch # Has a bunch of files I do not want to lose.

My desired state:

master # Empty
old_branch # Empty
new_branch # Has all the files that were in old_branch.

Solution:
It was a pretty painless process and straight forward. Git rocks!

$ git branch --list # See local branches
$ git branch --remotes # List the remote-tracking branches.
$ git checkout <old_branch>
$ git branch <new_branch>
$ git branch --delete <old_branch>
$ git push origin --delete <old_branch> 
$ git fetch origin --prune # After fetching, remove any remote-tracking references that no longer exist on the remote.
$ git push origin <new_branch>
$ git checkout master
$ git branch <old_branch> # Now old_branch is the same as master
$ git push origin <old_branch>
$ git branch --remotes
$ git branch --list

Source:
http://stackoverflow.com/questions/2003505/delete-a-git-branch-both-locally-and-remotely

Categories: git Tags:

SSL certificate problem: Invalid certificate chain

January 8, 2016 1 comment

Problem:

When trying to clone a repo I get the following error:

$ git clone https://user@organisation.org/path/to/repo/application.git
Cloning into 'application'...
fatal: unable to access 'https://user@organisation.org/path/to/repo/application.git/': SSL certificate problem: Invalid certificate chain

Solution:
As I was using a self generated ssl key

$ git config --global http.sslVerify false

Then tried again.

$ git clone http://user@organisation.org/path/to/repo/application.git
Cloning into 'application'...
Username for 'https://organisation.org': user
Password for 'https://user@organisation.org':
remote: Counting objects: 1397, done.
remote: Compressing objects: 100% (1034/1034), done.
remote: Total 1397 (delta 823), reused 164 (delta 98)
Receiving objects: 100% (1397/1397), 193.55 KiB | 43.00 KiB/s, done.
Resolving deltas: 100% (823/823), done.
Checking connectivity... done.

Source:
http://stackoverflow.com/questions/23331325/git-ssl-certificate-invalid-certificate-chain-while-accessing#25000465

Categories: git Tags:

git commands – Notes

December 3, 2015 Leave a comment

git commands that I normally forget 🙂

$ git init
$ git add <file>
$ git commit -m "commit message"
$ git rm --cached <file>
$ git status
$ git log
$ git branch
$ git branch <branch name> # To create a new branch
$ git checkout  # To switch to a different branch
$ git log --graph --decorate --pretty=oneline --abbrev-commit
# To create a command alias
$ git config <level> alias.<alias name> '<your sequence of git commands>' 
# eg to create git tree command
$ git config --global alias.tree 'log --graph --decorate --pretty=oneline --abbrev-commit'
$ git tree
$ git tag -d <tag name> # To delete a tag
$ git branch -d  <branch name> # To delete a branch

Update
Getting more and more used to working with git. A few more commands that are useful.

$ git rm -r --cached <dir> # To stop tracking a directory that was already committed.
                           # Does not delete the directory.
$ git update-index --assume-unchanged path/to/file.txt # To stop tracking future changes to a file.

Merging a branch. Assumption that it is a clean branch i.e. everything has been committed.

$ git branch
master
feature_1
*feature_2
$ git checkout feature_1
$ git merge feature_2

Deleting Remote and local branches.

$ git branch -d <branch>
warning: deleting branch '<branch>' that has been merged to
         'refs/remotes/origin/<branch>', but not yet merged to HEAD.
Deleted branch <branch>
$  git push origin --delete<branch>
 - [deleted]         <branch>

Tagging

# Adding
$ git tag -a v0.1 -m "Initial release 0.1"
# Deleting a local tag
$ git tag -d v0.1
# Deleting a remote tag (after you deleted it locally).
$ git push origin :refs/tags/v0.1

Source
http://stackoverflow.com/questions/1329291/ignoring-an-already-checked-in-directorys-contents
https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging
https://nathanhoad.net/how-to-delete-a-remote-git-tag

Categories: git