Thursday, June 29, 2017

Combine multiple commits into single one - squash your github commits




How to combine multiple commits into single one?

While carrying out a pull request, I ended up with 7 commits in the same pull request. 

I wish to combine all those 7 commits into a single one.( So it is easier to merge and unnecessary  history is removed)


# carrying out squash:

You want to squash all 7 commits into one:

# git rebase -i HEAD~7

 

It will launch a editor.

# Leave first commit as is.

# From 2 - 7 , change (edit) pick as squash

Now, It will squash the changes and launches editor for  adding commit message. (which actually contains all 7 commit messages).
You can edit the commit message as you wish.

Note: any commit message with # is comment. you need to delete unneeded commit message, else it will only add confusion.





# pushing changes:


Now, I have already pushed all those 7 commits into the github's pull request

So, I need to do force push:

# git push origin  <your branch name>  --force

that's it. :)

You can verify your github pull request. 
 

markdown preview in google-chrome


You are updating a markdown file and wish to preview how your changes look like.

You can install the below addon:

https://chrome.google.com/webstore/detail/markdown-preview-plus/febilkbfcbhebfnokafefeacimjdckgl?utm_source=chrome-app-launcher-info-dialog


You can edit markdown file using your favourite editor and  preview your changes live in your chrome browser.

Wednesday, June 21, 2017

Execute ansible-playbook faster




Execute ansible faster:

Set the below value in /etc/ansible/ansible.cfg (or) wherever your configuration file is:

------------------------------
[ssh_connection]
pipelining = True
------------------------------




How this helps? 

===========================

pipelining

Enabling pipelining reduces the number of SSH operations required to execute a module on the remote server, by executing many ansible modules without actual file transfer. This can result in a very significant performance improvement when enabled, however when using “sudo:” operations you must first disable ‘requiretty’ in /etc/sudoers on all managed hosts.
By default, this option is disabled to preserve compatibility with sudoers configurations that have requiretty (the default on many distros), but is highly recommended if you can enable it, eliminating the need for Accelerated Mode:

pipelining = False
===========================
Source:  http://docs.ansible.com/ansible/intro_configuration.html#pipelining

Bringup a network interface






========================

If the interface(for eg: eth0) is not UP automatically on system boot, you can temporarily  bring up the interface like:

# dhclient <eth0>

========================

To make it permanent, edit /etc/sysconfig/network-scripts/ifcfg-eth0
Set ONBOOT as yes as:
---------------------------
...
ONBOOT=yes
---------------------------

========================
Here, eth0 is the interface configured.


Tuesday, June 20, 2017

Progress of copy operation


See progress while carrying out copy operation: 

rsync --info=progress2 <source> <destination>

While using cp command, there is currently no direct way to check the progress..you can make use of rsync with 'info' flag as above to see the progress of copy operation.


Note:
rsync dir1/  dir2

This will copy contents inside dir1/ to dir2


rsync dir1  dir2

This will copy dir1 and its contents into dir2/

Tuesday, June 13, 2017

port opened in your machine



Check whether a specific port is opened on your machine:

You can make use of "netstat -tuplen"

# netstat -tuplen



For example, httpd (apache) server listens @ 80 port

# netstat -tuplen | grep httpd
tcp6       0      0 :::80                   :::*                    LISTEN      0          269550     15610/httpd        





Tuesday, June 6, 2017

sudo su to execute bash( and avoid sh)




Problem:

"sudo su" does not read /etc/bashrc and executes "sh" instead of bash



Solution:

You need to add the following lines in your /root/.bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi


that's it. 

Monday, June 5, 2017

save username/password while using github



--
You need to set this to store credentials in disk


git config credential.helper store


First time it will ask for credentials and stored in disk...afterwards same will be used.

This is applicable per github repo.

---

You can do the same globally by:

git config --global credential.helper store

cat ~/.gitconfig shoud reflect this.

---

Setting up fresh github repo


Setting up fresh github repo:


1. first visit github and create a user.

2. visit the url  like https://github.com/user_name_here

3. goto "repositories tab" - click on "new"

4. give a name "my_new_repository"


Avoid adding a README using UI. We will do it later from terminal.

5. Now you should be able to access this link:

https://github.com/user_name_here/new_repo.git



Now, open terminal and follow the *sample* workflow to freshly initialize your github repo:


echo "# simple_testing" >>  README.md
 

git init
 

git add README.md
 

git commit -m "first commit"

git remote add origin git@github.com:user_name_here/simple_testing.git


Another format for add: (this gives authentication failure. Avoid using it)

  git remote add origin https://github.com/user_name_here/simple_testing.git


git push -u origin master
 

Here, simple_testing is the "repo" name created.

Friday, June 2, 2017

github - keep your fork in sync



Keep your fork in sync. with original master :



# Now, you are in your local cloned copy of original GitHub repo:

git checkout master


You wish to update master to be in sync with original GitHub repo.



# First, add github location  as "remote"  (1)  - here *upstream* is the name provided by us:

git remote add upstream  https://github.com/original-repo-from-where-you-cloned.git



# fetch all branches - see we are using name provided above :)  (2)

git fetch upstream


# apply all changes from original github location to your branch and then play your changes on top

(3)

git rebase upstream/master

Now your fork is in sync with original repo :) - but only locally. You need to push the changes to get in sync.


// Check status
git status
On branch master
Your branch is ahead of 'origin/master' by 15 commits.
  (use "git push" to publish your local commits)
nothing to commit, working directory clean

// Push all changes you pulled from origin/master
git push

// Now check status again
git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean


You may check in GitHub UI, to check whether all changes are in.


=========================================================
Notes:

(1)  git-remote  add

Adds a remote named <name> for the repository at <url>. The command git fetch <name> can then be used to create and update remote-tracking branches <name>/<branch>.

(2) git-fetch - Download objects and refs from another repository

(3)  git-rebase - Reapply commits on top of another base tip

===============================================================
How to get your local test branch to be in sync with master ? 

So, lets say now your master branch is sync with *upstream* branch.

You want to make all changes you made to master to your localbranch (say testcodebranch).

So, do this:

# git co testcodebranch
# git rebase master

This way testcodebranch will be in sync with master.
 
 It will contain all the commits from the master branch + additional commit from you will be at the TOP.

===================================================================

// To apply a simple patch
git apply <path to filename.patch>


// to apply a git formatted patch - containing git header.
git am <path_to_filename.patch>

===================================================================


arp program in linux


arp program is used to read( and do more) arp cache, which is maintaining a table to ip address and corresponding mac address.

In order to get arp program, you need to install net-tools.

What other binaries provided by net-tools?

you can make use "dnf --list repoquery net-tools" command:

output :
# dnf repoquery --list net-tools

/usr/bin/netstat
/usr/lib/systemd/system/arp-ethers.service
/usr/sbin/arp
/usr/sbin/ether-wake
/usr/sbin/ifconfig
/usr/sbin/ipmaddr
/usr/sbin/iptunnel
/usr/sbin/mii-diag
/usr/sbin/mii-tool
/usr/sbin/nameif
/usr/sbin/plipconfig
/usr/sbin/route
/usr/sbin/slattach

/usr/share/licenses/net-tools
/usr/share/licenses/net-tools/COPYING
/usr/share/locale/cs/LC_MESSAGES/net-tools.mo
/usr/share/locale/de/LC_MESSAGES/net-tools.mo
/usr/share/locale/et_EE/LC_MESSAGES/net-tools.mo
/usr/share/locale/fr/LC_MESSAGES/net-tools.mo
/usr/share/locale/pt_BR/LC_MESSAGES/net-tools.mo
/usr/share/man/de/man5/ethers.5.gz
/usr/share/man/de/man8/arp.8.gz
/usr/share/man/de/man8/ifconfig.8.gz
/usr/share/man/de/man8/netstat.8.gz
/usr/share/man/de/man8/plipconfig.8.gz
/usr/share/man/de/man8/rarp.8.gz
/usr/share/man/de/man8/route.8.gz
/usr/share/man/de/man8/slattach.8.gz
/usr/share/man/fr/man5/ethers.5.gz
/usr/share/man/fr/man8/arp.8.gz
/usr/share/man/fr/man8/ifconfig.8.gz
/usr/share/man/fr/man8/netstat.8.gz
/usr/share/man/fr/man8/plipconfig.8.gz
/usr/share/man/fr/man8/rarp.8.gz
/usr/share/man/fr/man8/route.8.gz
/usr/share/man/fr/man8/slattach.8.gz
/usr/share/man/man5/ethers.5.gz
/usr/share/man/man8/arp.8.gz
/usr/share/man/man8/ether-wake.8.gz
/usr/share/man/man8/ifconfig.8.gz
/usr/share/man/man8/ipmaddr.8.gz
/usr/share/man/man8/iptunnel.8.gz
/usr/share/man/man8/mii-diag.8.gz
/usr/share/man/man8/mii-tool.8.gz
/usr/share/man/man8/nameif.8.gz
/usr/share/man/man8/netstat.8.gz
/usr/share/man/man8/plipconfig.8.gz
/usr/share/man/man8/rarp.8.gz
/usr/share/man/man8/route.8.gz
/usr/share/man/man8/slattach.8.gz
/usr/share/man/pt/man8/arp.8.gz
/usr/share/man/pt/man8/ifconfig.8.gz
/usr/share/man/pt/man8/netstat.8.gz
/usr/share/man/pt/man8/rarp.8.gz
/usr/share/man/pt/man8/route.8.gz