Git in Day to Day Life

Here is the quick list of commands that one need to use in day to day life. As I keep forgetting them, thought of listing down in one place.  Hopefully this list may save my time ;)

Configuring your identity 

$ git config --global user.name "FirstName LastName"
$ git config --global user.email firstname.lastname@somedomain.com

Clone repository

$ git clone

Create new branch

$ git  checkout -b feature/branch-name

Staging and committing changes

$ git  add .
$ git  commit -m "comments"
$ git push -u origin feature/branch-name

Viewing git log

$ git log --after="2020-01-01 00:00"
$ git log --all --pretty=format:"%h %cd %s (%an)" --since=7.days
$ git log --all --pretty=format:"%h %cd %s (%an)" --since='7 days ago'

Rebasing a feature branch

$ git checkout master
$ git pull
$ git checkout feature/branch-name
$ git rebase master
$ git add
$ git rebase --continue
$ git rebase master
$ git push origin feature/branch-name --force

Git pull with rebase

$ git pull --rebase

To abort rebase

$ git rebase --abort

Merging feature branch with master

$ git merge master

Squashing commits

$ git config --global rebase.instructionFormat "(%an <%ae>) %s"
$ git rebase -i HEAD~n

pick xxxxxxx Some commit comment1
pick xxxxxxx Some commit comment2

# Rebase xxxxxxx.. xxxxxxx onto xxxxxxx
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

$ git push origin feature/branch-name --force

Squashing All Commits on a Branch

$ git checkout feature/branch-name
$ git reset --soft id-of-first-revision-you-want-to-retain
$ git commit --amend -m "single commit for the branch"
$ git push origin feature/branch-name --force

Cherry pick a commit from master branch

$ git checkout feature/branch-name
$ git cherry-pick -x <commit-hash>

Reverting a commit

$ git revert <commit-hash>

Reverting changes made to a file in a Pull Request

$git checkout origin/master -- <path/fileName>
$git commit -a --amend
$git push -u origin HEAD -f


To checkout a specific commit for testing

$ git checkout <commit-hash>

Replacing master branch with feature brach

$ git checkout feature/branch-name
$ git merge -s ours master
$ git checkout master
$ git merge feature/branch-name

Ignoring file(s) from staging/commit

Add them in to  .git/info/exclude

Comments

  1. Our a day life is where we create and build our living conditions. However, what many folks do is postpone living our day to day life for a few faraway time. We are expecting the proper time to actually begin living. the matter is that our lifestyle is our real world , which we are ignoring or a minimum of the life we are letting slip away during a blur of unthinking and unappreciative haste.Inspiration can dig you out from a dull routine. the will for something better may provides a spark within the imagination which will project you on a special course. Everyone wants to be inspired in their day to day life. it's usually not something you'll find.check out Cheap Essay Writing Service it's something that finds you. it's going to happen once you are relaxing and enjoying a hobby. a thought may enter your head that changes everything.

    ReplyDelete
  2. Best price guarantee. We constantly monitor the pricing for academic writing services to make our service affordable for clients.
    write my paper

    ReplyDelete

Post a Comment

Disclaimer

The views expressed on this blog are my own and do not necessarily reflect the views of my employer.