Control characters in git commands


While working on a git-enabled project, it may happen sometimes that you modify a file and then see the changes using git diff or any other command then it shows control characters like “^M“. This may seem annoying.

You can hide it using:

git config core.whitespace cr-at-eol

On the successful completion of the above, commands like git diff and git show will stop showing these characters. But it will do on a per-project basis. If you want to do it globally, do:

git config --global core.whitespace cr-at-eol

 

Installing git-cola (git GUI client) on ArchBang


git-cola is a git client having a GUI. Visit https://github.com/git-cola/git-cola to install for a different distribution or for further detail. There are many other GUI clients. You may see them on https://git-scm.com/download/gui/linux

Now it requires sphinx (for documentation) to be installed. So install it using:

sudo pip install Sphinx==1.3.3

It depends on python2-pyqt4 package. So install it using:

sudo pacman -S python2-pyqt4

Install tk (if not already installed):

sudo pacman -S tk

Note: If you don’t install tk and run git-cola it’ll give error like:

/usr/bin/gitk: line 3: exec: wish: not found

Now install git-cola using yaourt:

yaourt -S git-cola

 

There are two commands: git-cola and git-dag.

git-cola includes all the workflow like showing currently unstaged files (on right) and after clicking one of them, it shows in the left large pane. Also it uses gitk to visualize the branches.

git-dag includes the visual representation of the git log command and shows the diagram of the commits and all that.

Using git for past


If you have some changes that you want to be shown as it were committed in past, then you may use this command:

GIT_AUTHOR_DATE='Mon Jan 26 16:32:33 2015 +0530' 
GIT_COMMITTER_DATE='Mon Jan 26 16:32:33 2015 +0530'
git commit -m 'commit message here'

It will commit the staged files committed as per the date given. Take care of the +0530, it should be your timezone.

If you want to change a commit from the log list then get the workaround here: http://stackoverflow.com/a/3896112/3784226

Gitignore


You might have noticed while creating a repository on GitHub, it asks if you want to add a license and a .gitignore file. So, what is a .gitignore file. It is basically a file that you create in your git repository to ignore some files and/or directories while committing.

If you make some changes to source some files and testing them by executing, then it’s more likely that you’ll have some additional files that you don’t want to be on GitHub. So you will simply put the files into a .gitignore file and  that’s it. Rest it’ll take care next time before committing.

If you don’t have a .gitignore file yet in your GitHub repository then you can just tell GitHub to create one for you. Just click the ‘+‘ button that you use to create a new file in that repository. Then in the name input box, type .gitignore and then a line will appear to tell you if you want a .gitignore file.

adding gitignoreClick on None and you’ll get a drop-down list with a search box. Enter the name of the language that you are working on. e.g. Python. After that, you need to just commit the file.

Now if you want to ignore some files with a particular extension, just add it to .gitignore.

For example: If you want to ignore all .pyc files within your repository, then you may add *.pyc in your .gitignore file.

You can also add a whole directory to the ignore list. e.g. You have a MAIN directory and within that directory you have folders like bin and you don’t know the number and/or location exactly. Then you may simply add the following the .gitignore file:

MAIN/**/bin/

This will ignore all bin folders within the MAIN folder recursively.

If you want your changes to take effect, you may need to execute the following command in the terminal:

git rm --cached -r .

It will just reload your git repository for the changes to take effect. It will remove all ignored files.

You can see a list of .gitignore files at: https://github.com/github/gitignore

Change Origin of a git repository


If you want to change the URL of a repository to which it points to, then this post is for you. If you try the same command:

git remote add origin http://github.com/USERNAME/OTHERREPOSITORY.git

then it is not gonna work and you will probably get error like this:

fatal: remote origin already exists.

List your existing remotes in order to get the name of the remote you want to change

git remote -v

Change your repository’s remote url with command:

git remote set-url origin https://github.com/USERNAME/OTHERREPOSITORY.git

Substitute the values of USERNAME and OTHERREPOSITORY with yours.

Beautify Readme.md on Github


Today I was updating the README.md file of the repository on Github and then I thought to make it look good. So I searched about it. After exploring I came to know that Github uses a language called ‘Markdown’ for these purpose and I browsed about how to use it. After getting the basic syntax, I started to write it in a website: http://tmpvar.com/markdown.html which gives live preview as we type markdown. You can see it in the image attached.

markdown live preview

Markdown Live Previw

You can see the live preview of the README.md at the github repository: http://github.com/rvirdiz/booking_system