Git : What is cherry pick

When specific commit from a certain branch and picked to some other branch it is called as cherry pick. Usually people work on different branches forked out of main branch in git repository. Now When we merge a branch in our branch we get all the commits, however when we pick specific commit from a branch to consumes or add it in our branch it is known as cherry pick.

There are several ways to do it, I would explain a simple way to do it using source tree.

1. Check out the branch you want to use or you want the commit to be picked up (consumed)
2. Choose to show all branches and not current branch only in drop down.
3. Now right click on the commit you want from other branch and select cherry pick option.
4. If there are not conflicts, every things is clean then you will get the cherry picked commit on your branch.
5. Push the commit to your origin.

 

  cherryPick

Advertisements

Git : How to configure Author name in git

Here are the simple steps to configure your author name in Git.

Configure the Name in Git to avoid unknown in author name

1. Click tools

2. Go to options

3. Click General

4. Insert your name and ep email id an save it

 

git

 

If you want to follow command line :
$ git config –global user.name "Aseem Jain"
$ git config –global user.email mail@premseem.com

Git : How to create a tag in git using source tree

Tag creation in GIT using source tree in simple steps :
1. select a commit to be tagged
2. right click and pick tag option
3. Provide tag name (lable)
4. Click add tag and push it to remote

gitTag

 

In case if you want to do the same using command prompt / shell the fire below commands

git clone <repo-address>

 

git tag -l

 

git checkout <tag-name>

 

git branch -D master

 

git checkout -b master

Git : How to Rename a git Branch

Renaming an existing branch in git repository is easy and simple. This method applies to renaming a branch in your local repository. Changes will reflect in the remote repository after you make a push.

If you are in the branch that you need to rename

git branch -m <new_branch_name>

If you are not in the branch that you need to rename

git branch -m <branch_you_want_to_rename> <new_name>

 

Note : Please remember, once you rename a branch, the branch with old name exists and a new branch with new name is also created. So please remember to delete the old branch from remote once renamed branch is created after the push.

Follow steps :

1. Switch to the branch you want to rename, then rename it it locally:

git checkout old_branch
git branch -m old_branch new_branch

2. Remove old branch from remote repository:

git push origin :old_branch

3. Push the renamed local branch to remote repository:

git push origin new_branch

Git status shows files as changed even though contents are the same

Problem Statement : “Git status” – shows a number of unwanted modified files 

After cloning the git repository if you fire git status and discovers that there are lot of modified files which you have not even touched/modified then the issue is definitely of Git Munging EOL (LF to CR/LF)

Step by Step solution –

1. Discard your local changes :
If you have any modification, take their back in some notepad file other then git repository, because in the process of solving this issues you might loose your commits, also this solution will not work if you have some modified changes in you repository.

2. Run below commands :

git rm --cached -r .
# Remove everything from the index. git reset –hard
# Write both the index and working directory from git's database.

3. Continue your work after pull
Now you can do a git pull and start adding code. Now with Git status you will not face the same problem again

Note : It may occur when you switch branches in git. So you might need to apply this solution every time you switch branch.

Cause:
If you’ve ever developed on Linux, and then switched to Windows, you’ll notice that as soon as you checkout your repository all of your files are marked as changed. This is due to Git munging your EOL (line endings) – changing them from LF to CRLF.

Ref: Incorrect handling of Windows/Unix CR/LF

GitHub : Generating SSH Keys

If you have decided not to use the recommended HTTPS method, we can use SSH keys to establish a secure connection between your computer and GitHub. The steps mentioed in the link will walk you through generating an SSH key and then adding the public key to your GitHub account.

Link : https://help.github.com/articles/generating-ssh-keys

image

Git : Going back in time

time_traveser_in_git

Git makes it simple to do a time travel seamlessly. One can easily get to any state of application without much hassles, just by a simple click of git. Actually git preserves the delta of code and applies it when any checkout that revision.
Traditionally if as a developer I have made changes before the demo and found out at the last moment that application is screwed. Now it is difficult to take previous version of all files where app was stable using SVN since there is nothing like local commit. However with “SVN update revisionnumber” one can get back the remote application state. With git making restore point by local commit and reverting back to it is possible. This eliminates the need to take a backup at every stable state since it can be attained at any point in time at any development sand box itself. In short with git you can have restore point in your local machine as well by the means of local commits.

git reset <revision number>

git –hard <revision number>