Skip to content

Instantly share code, notes, and snippets.

@nucliweb
Last active July 29, 2016 16:31
Show Gist options
  • Save nucliweb/7be1836fe7417e3d73d4 to your computer and use it in GitHub Desktop.
Save nucliweb/7be1836fe7417e3d73d4 to your computer and use it in GitHub Desktop.
Git Tips

Git notes

git init                          <-- Create repo

git add .                         <-- Add change to
git commit -m "Message"          <-- Commit to repo
git commit -m "Message" <files>  <-- Commit to repo
git commit -am "Message"         <-- Add files & Commit to repo
git commit -a --amend             <-- Add change to Commit, option to change de description of Commit
git reset --hard HEAD^            <-- Remove last commit
git reset --hard <sha1>



git log                           <-- Show all commints
git log --oneline                 <-- Show all commints, on line description
git log -3                        <-- Show the last 3 commints

git show-brand --more=5


git pull mozilla master			  	<-- Sync Remote with Local repo
git pull -r mozilla master			<-- Rebase remote branch to current branch
git push origin master -f 		  <-- Sync Local with Remote repo (-f = force)

git reset --hard ad116b3        <-- Move HEAD to specific commit and delete all previous commits and files
git reset --soft ad116b3		  	<-- Move HEAD to specific commit and move files on index/staging area
git reset --mised ad116b3	      <-- Move HEAD to specific commit and move files on working directory

git pull --rebase mozilla master


git branch 					      		          <-- Show list of branches
git branch <branch_name>		  		      <-- Create a new brach
git branch -D <branch_name>				      <-- Delete brach
git push origin --delete <branchName> 	<-- Delete remote branch

git merge <branch_name>			  		<-- Merge branch to current branch


git tag
git tag -a '<TAG_NAME>' -m '<description>'

git tag -d <TAG_NAME>                    <-- Delete from local
git push --tags origin :tags/<TAG_NAME>  <-- Push deleted tag to origin



git rebase -i HEAD~4              <-- Group the last 4 commits
git rebase -i HEAD~2              <-- Group the last 2 commits


git remote -v                     <-- Show de remote repositories
git remote add origin <url>       <-- Add remote repository
git remote add mozilla https://github.com/mozilla-b2g/gaia.git


git clone -b buttons-refresh-1 https://github.com/rnowm/gaia.git  	<-- Clone specific branch from remote
git clone -b mybranch --single-branch git://sub.domain.com/repo.git <-- Clone specific branch from remote


git log -S 'STRING' --oneline -- <path><file>
ej: git log -S 'body[role="application"] .button input {' --oneline -- shared/style/buttons.css



git format-patch <branch> --stdout > <file> 	<-- Patch current branch to parse branch


git stash 										<-- Move to temps zone
git stash list
git stash save "mensaje”
git stash pop
git stash show stash@{0}
git stash apply stash@{0}
git diff stash@{0}

git apply ../patches/dialer-refresh.patch


git branch -D master
git push origin :master
git push mozilla master

$ git branch -a
* master
  remotes/origin/HEAD
  remotes/origin/master
  remotes/origin/v1.0-stable
  remotes/origin/experimental

If you just want to take a quick peek at an upstream branch, you can check it out directly:

$ git checkout origin/experimental But if you want to work on that branch, you'll need to create a local tracking branch:

$ git checkout -b experimental origin/experimental Now, if you look at your local branches, this is what you'll see:

$ git branch

  • experimental master

Borja -----------------

  1. git checkout -b MI_NUEVA_RAMA (estando en master)
  2. git pull --rebase mozilla master
  3. HAGO EL CURRO QUE NECESITE
  4. git push repo_joan MI_NUEVA_RAMA
  5. desde github envio Pull request

List branches & revision date #git

git for-each-ref --sort='-authordate:iso8601' --format=' %(authordate:iso8601)%09%(refname)' refs/heads


git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"

List all the files in a commit

git show --name-only <commit-ish>
git show --pretty="" --name-only <commit-ish>
git diff-tree --no-commit-id --name-only -r <commit-ish>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment