Skip to content

Instantly share code, notes, and snippets.

@pongstr
Forked from itsvicsoto/git-magic.md
Last active August 29, 2015 14:14
Show Gist options
  • Save pongstr/9fcb18b839cc361f7db5 to your computer and use it in GitHub Desktop.
Save pongstr/9fcb18b839cc361f7db5 to your computer and use it in GitHub Desktop.

Git Magic

How to fetch remote changes?

 > git fetch --all
 > git fetch --tags

How to move and push a tag?

 > git tag -f -a <version v1.0.0>
 > git push -f —-tags

How to remove and untrack files?

 > git rm --cached "<file_path>"

Adding submodule

 > git submodule add <git_url> <directory_path>

Squashing

Squashing with previous commmit messages

# Reset the current branch to the commit just before the last 12:
> git reset --hard HEAD~12

# HEAD@{1} is where the branch was just before the previous command.
# This command sets the state of the index to be as it would just
# after a merge from that commit:
> git merge --squash HEAD@{1}

# Commit those squashed changes.  The commit message will be helpfully
# prepopulated with the commit messages of all the squashed commits:
> git commit

Useful GitChain of Commands

Fork Workflow

1. Adding your remote git repository for both your origin and upstream

Make sure your remote repository ssh/https are correct.

> git remote show

# It should display two remote repository namely origin and master
# if not you should remove all remote repository and manually add
# each which is origin (your fork repository)
# and upstream (which is the one you forked)

# Now if you do the following command it should display the correct
# remote reference

> git remote show origin
* remote origin
  Fetch URL: git@bitbucket.org:organisation/your_forked_repository.git
  Push  URL: git@bitbucket.org:organisation/your_forked_repository.git
  HEAD branch: master

> git remote show upstream
* remote upstream
  Fetch URL: git@bitbucket.org:organisation/the_one_you_forked.git
  Push  URL: git@bitbucket.org:organisation/the_one_you_forked.git
  HEAD branch: master

2. Get updates from upstream/branch (usually master)

# This should tell you whether your origin or upstream has an update
# if yes you'll see the message

> git fetch --all


Resources

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