Skip to content

Instantly share code, notes, and snippets.

@nipunsadvilkar
Created March 29, 2017 11:20
Show Gist options
  • Save nipunsadvilkar/3b654155be22cd9a86692801e72668ef to your computer and use it in GitHub Desktop.
Save nipunsadvilkar/3b654155be22cd9a86692801e72668ef to your computer and use it in GitHub Desktop.

create a new repository on the command line

echo "# sample_git_tweak" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:nipunsadvilkar/sample_git_tweak.git
git push -u origin master

push an existing repository from the command line

Create repository in Github or any other repository hub website and use its ssh/HTTP link below.

git remote add origin git@github.com:nipunsadvilkar/sample_git_tweak.git
git push -u origin master

Pushing Remotely

The push command tells Git where to put our commits when we're ready, and boy we're ready. So let's push our local changes to our origin repo (on GitHub).

The name of our remote is origin and the default local branch name is master. The -u tells Git to remember the parameters, so that next time we can simply run git push and Git will know what to do. Go ahead and push it!

git push -u origin master

Pulling Remotely

Let's pretend some time has passed. We've invited other people to our GitHub project who have pulled your changes, made their own commits, and pushed them.

We can check for changes on our GitHub repository and pull down any new changes by running:

git pull origin master

Differences

Uh oh, looks like there have been some additions and changes to the octocat family. Let's take a look at what is different from our last commit by using the git diff command.

In this case we want the diff of our most recent commit, which we can refer to using the HEAD pointer.

git diff HEAD

Undo file after removal from git

In case you remove file with

$git rm filename

you can revert it by using command:

$git reset --hard HEAD

Rollback to an old Git commit in a public repo

hard reset to previous branches instead of doing revert many times, use:

git checkout [revision] .
where [revision] is the commit hash (for example: 12345678901234567890123456789012345678ab).

Don't forget the . at the end, very important. This will apply changes to the whole tree. Then commit and you should be good.

You can undo this by

git reset --hard; 
that will delete all modifications from the working directory and staging area.

Refer: http://stackoverflow.com/questions/2007662/rollback-to-an-old-git-commit-in-a-public-repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment