Skip to content

Instantly share code, notes, and snippets.

@ashish2199
Created November 26, 2017 09:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save ashish2199/4569397328990f25505582f39c069fb2 to your computer and use it in GitHub Desktop.
Save ashish2199/4569397328990f25505582f39c069fb2 to your computer and use it in GitHub Desktop.
To initialise a new git repository
git init
To download a repository from a website
git clone https://github.com/tutorialzine/awesome-project.git
To remove commits from github.
git log
to find out the commit you want to revert
git push origin +7f6d03:master
while 7f6d03 is the commit before the wrongly pushed commit. + was for force push
To remove staged files
git reset
To make a new branch with uncommitted changes
git checkout -b <new-branch>
git add <files>
git commit -m "<Brief description of this commit>"
The name of our remote is origin and the default local branch name is master.
Adding a remote
git remote add origin https://github.com/try-git/try_git.git
Uploading changes to server using git push
It takes two parameters - the name of the remote repo (we called ours origin) and the branch to push to (master is the default branch for every repo).
git push origin master
Getting changes from the server
git pull origin master
The default branch of every repository is called master.
To create a new branch
git branch <branchname>
To delte a branch
git -d <branchname>
To see list of branches
git branch
To switch to a different branch
git checkout <branchname>
To see changes made by a commit
git show <commitID>
To get diff of our most recent commit
git diff HEAD
To see the changes you just staged and last commit
git diff --staged
To remove staged files (preserves it files content)
git reset <filename>
To remove chagnes from all commits afer [commit], (preserving changes locally so working directory not changed)
git reset [commit]
To remove changes from working directory as well
git reset --hard [commit]
To change File to how they were at the last commit
git checkout -- <filpath>
To change particular file to a particular version
git checkout 09bd8cc1 hello.txt
To change everything to how they were at the last commit
git checkout .
To merge given branch into current branch
git merge <branchname>
To delete a branch
git branch -d <branchname>
To make changes to previous commit without commiting a new one.
This will add everything from the last commit back to the staging area, and attempt to make a new commit. This gives you a chance to fix your commit message or add more files to the staging area.
git commit --amend
To configure some global emails , password and name
git config --global user.name "Ashish Padalkar"
git config --global user.email ashish2199@gmail.com
git config --global core.editor "'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -nosession"
git config --global color.ui auto
To revert changes made by a commit
This will take all the changes that a commit has introduced, reverse them, and create a new commit that is the exact opposite.
git revert HEAD
To see version history of current branch
git log
To see one line version history
git log --oneline
To Lists version history for a file, including renames
git log --follow [file]
To remove file from version control
git rm --cached <file>
Temporarily stores all modified tracked files
git stash
Lists all stashed changesets
git stash list
Restores the most recently stashed files
git stash pop
Discards the most recently stashed changeset
git stash drop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment