Skip to content

Instantly share code, notes, and snippets.

@jkusachi

jkusachi/git-notes.md

Last active Sep 19, 2016
Embed
What would you like to do?

View local branches

git branch

  • the one with the * next to it is your current HEAD

View remote branches

git branch -r

  • repositories that are hosted on the repo will be preceded with origin/

##Create and checkout branch (based off of remote) git checkout development/3.8.0

Branch development/3.8.0 set up to track remote branch development/3.8.0 from origin. Switched to a new branch 'development/3.8.0'

What this will do is create and track based off of the remote branches.

Viewing Current Status

git status

main points are Untracked files and Modified files

Untracked - Brand New files that haven't been on the repo ever. If you want to delete them, you simply delete them and they're gone.

Modified - Files that have already been added via git add, and committed.

Undoing changes

If you wish to revert a file to it's last committed state (applies to Modified files)

git checkout /path/to/file.ext

Push to a remote

git push <REMOTENAME> <BRANCHNAME>

git push -u origin feature/my-new-feature

Renaming

In the case you want to rename a branch on the remote

git push origin feature/my-new-feature:feature/my-renamed-feature

Tracking

By default git wont set up tracking for you (so if others push to the same branch, you wont know about the changes)

to do so, add -u

git push -u origin feature/my-new-feature

Pulling remote changes

git pull
git pull <REMOTENAME> <BRANCHNAME>

If you wish to pull your currently tracked branch:

git pull

If you wish to specify exactly which branch:

git pull origin development/3.8.0

Merging

git merge <BRANCHNAME>

Rule of thumb is you merge INTO your HEAD.

For example, you ran git branch

  development/3.8.0
* feature/my-feature
  master

This would mean our HEAD is our feature branch, feature/my-feature.

Let's say we want to update development/3.8.0 with our feature branch

first, we would

git checkout development/3.8.0
git merge feature/myfeature

at this point, the merge is complete

now if we ran

git status

we will see: Your branch is ahead of 'origin/development/3.8.0' by # commit.

now we can run

git push

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.