Skip to content

Instantly share code, notes, and snippets.

@ShawnClake
Last active October 28, 2018 16:15
Show Gist options
  • Save ShawnClake/dc1e38c6e32f4a5d09e58a433d40f875 to your computer and use it in GitHub Desktop.
Save ShawnClake/dc1e38c6e32f4a5d09e58a433d40f875 to your computer and use it in GitHub Desktop.
Github cheatsheet

Github command cheatsheet

Branching

If another_branch already exists locally and you are not on this branch, then git checkout another_branch switches to the branch.

If another_branch does not exist but origin/another_branch does, then git checkout another_branch is equivalent to git checkout -b another_branch origin/another_branch;git branch -u origin/another_branch. That's to create another_branch from origin/another_branch and set origin/another_branch as the upstream of another_branch.

If neither exists, git checkout another_branch returns error.

git checkout origin another_branch returns error in most cases. If origin is a revision and another_branch is a file, then it checks out the file of that revision but most probably that's not what you expect. origin is mostly used in git fetch, git pull and git push as a remote, an alias of the url to the remote repository.

git checkout origin/another_branch succeeds if origin/another_branch exists. It leads to be in detached HEAD state, not on any branch. If you make new commits, the new commits are not reachable from any existing branches and none of the branches will be updated.

The above was taken from: https://stackoverflow.com/questions/47630950/how-can-i-switch-to-another-branch-in-git

Moving code developed on an older branch to a newer branch

  • git stash
  • git fetch - If the branch was created outside of the local repo and the local repo needs to become aware of it
  • git checkout <branch_name>
  • git stash pop

Adding Items To Gitignore

First: git rm -r --cached . git add .

Then: git commit -am "Remove ignored files"

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