Git tutorials and examples

Github tutorial for beginners

Using git/github may look like a daunting task but once you set it up, it is not that difficult. Here are quick steps to get read more

Git – how to undo last commit

Sometime we need to undo last commit in git. This is fairly useful to undo a change made accidentally. Here are quick instructions to do read more

How to list git branches

These are various command to list git local and remote branches. Note that local branches may be different from remote branches. List git local branches read more

Git – checkout remote branch

To checkout remote branch and track it from its remote origin $ git fetch $ git branch -v -a ##List available remote branches $ git read more

git – how to diff two branches

It is sometimes useful to be able to diff two branches in git. This can be useful to understand the changes in a git repository read more

Git – show log of one user’s commits

git log –author=pattern can be used to show log of all users matching a specific pattern. $ git log –author=Ram $ git log –author=”R.*m” // read more

Git – how to view diff for a given commit id

Diff commit id with its first parent commit id Here are some approaches to view diff between first parent of commit id and commit id. read more

How to setup password less git push for github

You can use user and password based authentication to push git changes to GitHub. But it is cumbersome to type user and password with every read more

Git – Check if a hash is valid

Use git show and check for exit status $ git show -s 97d79ecf6b6 commit 97d79ecf6b6c5cc3c1485eb3c46e12986a978f57 Author: Dave Methvin Date: Mon Nov 9 17:49:01 2015 -0500 read more

Git – display specific length commit hash

Display last commit from head to with specific commit hash length $ git log –pretty=format:”%h” –abbrev=7 -1 97d79ec

Git – rename local branch

Git – rename local branch $ git branch -m oldname newname

Git create branch

Create branch without switching $ git branch NEWBRANCHNAME ## list branches $ git branch Create branch and switch to it $ git checkout -b NEWBRANCHNAME read more

Git delete branch

Delete local branch $ git branch -d BRANCHNAME ## list branches $ git branch

Git detached head

Create a detached head situation $ git branch * master $ git log –oneline 55fff69 v3 1fd2aa6 file1 $ git checkout 1fd2aa6 Note: checking out read more

Git display info of last commit (HEAD) in one line

Display last commit info from head in one line $ git log –pretty=format:”%h|%an|%ad|%s” -1 97d79ec|Dave Methvin|Mon Nov 9 17:49:01 2015 -0500|Dimensions: Empty sets should return read more

Git display local HEAD location

Display HEAD pointer $ cat .git/HEAD ref: refs/heads/foo1 Display HEAD pointer (detached head case) $ cat .git/HEAD 1fd2aa6a8ff7205c91fde3d9557c6d67eeaf4eb1

Git log with file names

git log with name $ git log –name-status … git log with name (one entry) $ git log –name-status -1 commit fbf829b7245f7d76ea02a44ab0a62427214b7575 Author: Timmy Willison read more

Git show details of a commit hash

show a commit details (without file diff) $ git show -s 97d79ecf6b6 commit 97d79ecf6b6c5cc3c1485eb3c46e12986a978f57 Author: Dave Methvin Date: Mon Nov 9 17:49:01 2015 -0500 Dimensions: read more