Skip to content

Instantly share code, notes, and snippets.

@bnguyensn
Last active July 8, 2020 21:08
Show Gist options
  • Save bnguyensn/29362047f503a9dd77c9d13a37c85446 to your computer and use it in GitHub Desktop.
Save bnguyensn/29362047f503a9dd77c9d13a37c85446 to your computer and use it in GitHub Desktop.
Simple git

1. START

1. Update master branch

Make sure all changes have been saved before this either per section 2.2 or 3.2 below.

git checkout master
git pull

Now perform steps in section 2 if no local branch exists, or section 3 if a local branch exists.

2. WORK ON NEW BRANCH

2.1 Create new branch

Branch names must not have spaces.

git checkout -b my-new-branch

2.2 Stage all changes and commit

This saves your changes to git. Do this before any push or merge.

git add .
git commit -m "my commit message"

2.3 Push to remote

This uploads your branch to GitHub.

git push -u origin HEAD

3. WORK ON EXISTING BRANCH

3.1 Switch back to and update existing branch

git checkout my-new-branch
git merge master

3.2 Stage all changes and commit

This saves your changes to git. Do this before any push or merge.

git add .
git commit -m "my commit message"

3.3 Push to remote

This uploads your changes to GitHub.

git push

4. MISC.

4.1 Delete a branch

git branch -D my-new-branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment