Skip to content

Instantly share code, notes, and snippets.

@geocine
Last active March 16, 2019 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save geocine/5628522 to your computer and use it in GitHub Desktop.
Save geocine/5628522 to your computer and use it in GitHub Desktop.
git workflow
GIT
===
touch README.md # create file
git init # initialize/mark/track directory as a git repository
git status # show file status
git add README.md # mark a file to be tracked
git commit -m "first commit" # commit to local repository with commit message
git remote add origin git@github.com:geocine/try_git.git # add remote repository
git push -u origin master # push (-u changed files) to remote repository on a specific branch (master)
git pull origin master # pull from remote repository
git add octofamily/octodog.txt # add specific file to index(staging)
git diff --staged # in order to see the changes that have been staged already
git reset octofamily/octodog.txt
git checkout -- octocat.txt
git branch clean_up
git rm "*.txt"
git checkout master
git merge clean_up
git branch -d clean_up
git archive --format zip --output /full/path/to/zipfile.zip master
git archive -o latest.zip HEAD
git commit -am "comment"
git commit -b "new branch"
git commit -ammend -m "new commit"
git checkout X
git checkout -b new-branch
git commit
git add; git mv; git rm;
git pull --rebase
git rebase origin/master
git push origin X
# remove reset and rollback commits
git reset --hard HEAD~1 # remove last commit (all uncommited changes will be lost)
git reset --soft HEAD^ # remove last commit (leave the changes in the index)
git reset HEAD^ # remove last commit (leave the changes in the working directory)
# working on something not done yet
git stash
git stash pop
git stash list
git stash save "name"
git stash pop stash@{1} # get specific stash index
#shortcuts
pressing Q would exit from diff and git log
git ls-files -m #show only modified files
git ls-files -u #which files need merging
git branch #get current branch
git checkout --ours . # checkout our local version of all files
git add -u # mark all conflicted files as merged/resolved
git commit # commit the merge
git reset --hard HEAD # undo that failed merge
git push --force # replace everything remote with local
http://gitimmersion.com/lab_05.html
git-svn
[with -s tells its basic structure must use url up to /svn only]
git svn clone -s --username=aivan https://domain.com/svn folder-name
git svn info
git svn rebase
git add .
git commit -am
git svn dcommit
git rebase -i HEAD~10 # Mixed Commits
# creating svn branch in git
git svn branch -m "Branch for work on extra cool feature" extra_cool_feature
git checkout --track -b extra_cool_feature_local remotes/extra_cool_feature # to avoid warning from git about ambiguity
git reset --hard remotes/extra_cool_feature
... hack/git commit/git commit --amend/git rebase -i HEAD~10/... as usual
Merging trunk into branch
git checkout master
git svn rebase
git checkout extra_cool_branch
git merge --squash master
git commit -m "Bring branch up-to-date with trunk"
Merging branch back to trunk
git checkout master
git svn rebase
git merge --squash extra_cool_feature
git commit -m "Merge branch into trunk"
Stashing your work then applying it to a new branch
git stash
git branch
git stash apply x
http://stackoverflow.com/questions/2530060/can-you-explain-what-git-reset-does-in-plain-english
#ssh
cd /c/Users/[User]/.ssh
OR
cd ~/.ssh
rm id_rsa*
ssh-keygen -t rsa -C "geocipher@gmail.com"
ssh -T git@github.com
gem install heroku
git clone git://github.com/ckhsponge/long-noodle.git
cd long-noodle
heroku create --stack cedar
git push heroku master
heroku config:add TOKEN=NOODLE
heroku ps:scale web=1
git remote rm origin
Merging commits
git rebase -i HEAD~5
allows you to interactively select which of the 5 last commits to join into one; off the top of my head it opens the editor with something like this
pick xxxx commit1
pick xxxx commit2
pick xxxx commit3
pick xxxx commit4
pick xxxx commit5
you change this into
pick xxxx commit1
squash xxxx commit2
squash xxxx commit3
squash xxxx commit4
pick xxxx commit5
which results in two commits being left: first one that has combined commits 1 - 4, and commit 5 (the newest one) which is left alone
git log (press q to end)
You could git fetch origin to update the remote branch in your repository to point to the latest version. For a diff against the remote:
git diff origin/master
Yes, you can use caret notation as well.
If you want to accept the remote changes:
git merge origin/master
git diff ..origin/master
merge file in git
git rm file
git rm --cached file (remove from repo but not from system)
# Remove last commit from remote git repository
git reset HEAD^
git push origin +HEAD
# If you want to still have it in your local repository and only remove it from the remote, then you can use:
git push origin +HEAD^:<name of your branch, most likely 'master'>
# May need to do a git pull before git push
#Fix git ignore
git rm -r --cached .
git add .
git commit -m "fixed untracked files"
for cygwin git
git config --global core.filemode false
git config --global core.autocrlf true
git config --global core.whitespace cr-at-eol
git checkout -t origin/future_branch (for example)
git fetch origin
git branch -v -a
git checkout -b test origin/test
git fetch
git checkout test
#git pull with rebase , use when your changes do not deserve a separate branch
git pull --rebase <remote name> <branch name>
#removing tag
git tag -d release01
git push origin :refs/tags/release01
#list tag
git tag -n
#replace tag
git tag new old
git tag -d old
git push origin :refs/tags/old
git push --tags
#git add interactive
git add -i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment