Saturday, January 7, 2017

Git for Beginners Or Git at a glance.

Git is a "distributed" VCS. You can run it locally and disconnected from the Internet, and then "push" your changes to a remote system (such as GitHub) .
It's a source code management system for software development.
A git repository contains, among other things, the following: A set of commit objects. A set of references to commit objects, called heads.
Here i am listing down some Git commands with brief text about what that command does.

1. Remove Git Tracking
$ rm -rf .git

2. Show Origin of the repository
$ git remote show origin

3. Adding files to Git
$ git add <filename>
$ git add *

4. Commit files
$ git commit -m "Commit message."
$ git commit -a

5.Status i.e list the files you've changed and those you still need to add or commit:
$ git status

6. Push i.e.send changes to the remote master branch of your remote repository:
$ git push origin master/dev/prod/branchName

7. Connect to a remote repository to be able to push to it:
$ git remote add origin <server>

8. List all currently configured remote repositories
$ git remote -v

9. List all the branches in your repository, and also tell you what branch you're currently in:
$ git branch

10. Create a new branch and switch to it:
$ git checkout -b <branchname>

11. Switch from one branch to another:
$ git checkout <branchname>

12. Delete the feature branch:
$ git branch -d <branchname> (not the remote branch!)

13. Push the branch to your remote repository, so others can use it:
$ git push origin <branchname>

14. Push all branches to your remote repository:
$ git push --all origin

15. Delete a branch on your remote repository:
$ git push origin :<branchname>

16. Fetch and merge changes on(from) the remote server to your working directory:
$ git pull

17. To merge a different branch into your active branch:
$ git merge <branchname>

18. View all the merge conflicts:
$ git diff

19. View the conflicts against the base file:
$ git diff --base <filename>

20. Preview changes, before merging:
$ git diff <sourcebranch> <targetbranch>

21. Tags. You can use tagging to mark a significant change set, such as a release:
$ git tag 1.0.0 <commitID>

22. Push all tags to remote repository:
$ git push --tags origin

23. Git add remote upstream
$ git remote add upstream https://github.com/nirmalyamondal/Drupal-Modules.git

24. If you want to see more information about a particular remote, you can use the git remote show [remote-name] command.
$ git remote show origin\

25. Undo local changes
If you mess up, you can replace the changes in your working tree with the last content in head:
Changes already added to the index, as well as new files, will be kept.
$ git checkout -- <filename>

26. Check the log of the Git commit 
$ git log

27. Tell Git who you are
git config --global user.name "Nirmalya Mondal"
git config --global user.email nirmalya_email@domain.com
git config --list

28. Create a new local repository
$ git init

29. Instead, to drop all your local changes and commits, fetch the latest history from the server and point your local master branch at it, do this:
$ git fetch origin
$ git reset --hard origin/master

30. Check out a repository
$ git clone /path/to/repository
$ git clone username@host:/path/to/repository

31. Removes all removed remote branches
$ git fetch --all --prune

32. Stashes the local changes, so they can’t be lost during a git pull.
$ git stash

33. Restores the changed files from the stash and tries to merge them.
$ git stash apply

34. Reverts an commit that is already committed and pushed.
$ git revert <hash>

35. Removes the given files from the remote repository
$ git rm <file1> <file2>

Don't be confused with pull and fetch command. In the simplest terms, git pull does a git fetch followed by a git merge.

Git's Workflow that i follow is like -
-------------
Forking the repository -> cloning it -> creating feature branches -> committing changes -> submitting pull requests.
-------------

More commands to be added soon ... 

Some useful Ubuntu commands we use frequently.

There are some Ubuntu commands we use very frequently and its harder to remember these all. To avoid searching over the net i am writing those down here precisely for reference so that i can have a look at it anytime.

1. Setting file permissions to 664 recursively -
$ find . -type f -exec chmod 664 {} \;

2. Setting folder permissions to 775 recursively -
$ find . -type d -exec chmod 775 {} \;

3. Delete files folders recursively -
$ rm -rf folderName

4. Search for a "string" in your system -
$ grep -nr "string"

5. Generating An ISO file From A Folder
$ mkisofs -o image.iso -R /path/to/folder/
$ mkisofs -o image.iso -R $HOME (for home directory)

6. Download and extract Tar file in a command
$ wget url-to-tar-file -O - | tar xfz -
$ wget http://website.com/project/tarFile_4.7.tar.gz -O - | tar xfz -

I also prefer dtrx to unzip files. Because with a single command you can unzip any zipped file format.
To install that use this command
$ sudo apt-get install dtrx

7. Killing a halted process
Top command to list down all process with its id.
$ top 
$ kill -SIGKILL procesid
Or we can use this command below as well
$ kill -SIGTERM procesid

8. Symlink through command
To create a symlink at /foo/bar which references to file /usr/bin/bar use this command below
$ ln -s /usr/bin/bar /foo/foo

9. Reading file say error log of Apache webserver
$ tail -f /var/log/apache2/error.log


10. Export Import mySql data file -
$ mysqldump -u root -p password databaseName > database_filename.sql
$ mysql -u root -p password -h localhost databaseName < database_filename.sql

Many more to add ...