makrandp / working-with-git

Working With Git

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Working with Git

Alias

[alias]
	st = status
	pu = config user.email "makrandapatil17@gmail.com"
	pu2 = config user.id "makrandp"

Add file to staging

  • git add filename

To unstage a file BEFORE COMMIT

  • git rm --cached filename (this will remove file after the commit)

To unstage a file AFTER COMMIT

  • git reset HEAD -- filename

Checkout remote branch

  • git checkout --track origin/branch-name

To discard changes to all files which are tracked and commited

  • git checkout -- .

To discard changes to a file which is tracked

  • git checkout -- path/to/file

Scenario with Remove/Delete

delete your tracked files

  • git rm

If your file is in staging area then you have to give additional force flag.

  • git rm -f

delete files from git repository but not from your file system.

  • git rm --cached

Git Logs

  • git log --oneline
  • git log --oneline --graph --decorate --all

you want to see the commit message of a specific author

  • git log --author="John Doe"
  • git log --pretty=format:"%h%x09%an%x09%ad%x09%s" --author="Mak Patil"

Merge branch

I always merge with --no-ff(no fast forward)

  • git merge --no-ff

Git reset

Reset branch to a particular commit

Reset Everything

  • Have you ever started working on a branch, making changes, but you change your mind and want to completely start over? Use this command to remove any changes and reset the branch to a clean state.
    • git reset --hard HEAD

Useful commands

About

Working With Git