Skip to content

Instantly share code, notes, and snippets.

@abelberhane
Forked from psychok7/GIT Commands
Created January 23, 2018 16:02
Show Gist options
  • Save abelberhane/ea8f122fd81d6650c6a6b389fd903a70 to your computer and use it in GitHub Desktop.
Save abelberhane/ea8f122fd81d6650c6a6b389fd903a70 to your computer and use it in GitHub Desktop.
GIT Quick Commands
#On local machine
cd foo (your project folder parent)
git init
git add -A * (doesnt add empty folders, be carefull with netbeans config files)
git commit -m "My initial commit message"
#On local machine, in your git project
git remote add origin https://psychok7@bitbucket.org/psychok7/human-computer-interaction.git
git push origin master
#delete files
git ls-files --deleted
git ls-files --deleted -z | xargs -0 git rm
git commit -m "removed some files"
#remove remote reference
git remote rm origin
#branches
$ git checkout -b iss53
Created and switched to a new branch "iss53"
$ git checkout master
$ git merge iss53
$ git branch -d iss53
#Clone all remote branches
$ git clone git://example.com/myproject
$ cd myproject
$ git branch
$ git branch -a
$ git checkout -b experimental origin/experimental
#git checkout remote branch
git fetch origin
git checkout -b test origin/test
#Pull updates to forked branch from Master repository (vice-versa)
git remote
git remote add upstream https://github.com/octocat/Spoon-Knife.git
git pull upstream master
#ignore uncommited changes (exluding added files)
git stash #save uncomitted changes
git stash clear #delete uncomitted changes
git reset --hard #revert to previous commit
#REVERT TO PREVIOUS REVISION
git reset --hard 84fe56769ef2
git status
git clean --force -d
git push --force origin master
#Remove specific commits
git rebase --onto fb04823fb1e6cfc17c7c55e425b1dc9f79cd46ac^ fb04823fb1e6cfc17c7c55e425b1dc9f79cd46ac # commit to remove
git checkout -b new_branch # we will delete the old branch so we create a new one first with the previous commit already removed
git branch -D old_branch
git push origin new_branch
# Squash commits with rebase
# http://stackoverflow.com/questions/6934752/combining-multiple-commits-before-pushing-in-git#answer-6934882
In the end dont't forget to force the push to the repo with :
git push --force origin <branch>
#reset specific file
git checkout ef3ac2a8b1 networklocum/jobs/views.py
#renamed files or deleted
git add -A *
#remove folder
git rm -r cache/
#everyday usage:
#######################################################################
git add *
git commit -m "My initial commit message" (commit to local repository)
git push origin master (push to remote server)
#######################################################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment