Skip to content

Instantly share code, notes, and snippets.

@jwill9999
Last active November 4, 2019 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwill9999/bca1ab002bda43e23771cfeed28bbb77 to your computer and use it in GitHub Desktop.
Save jwill9999/bca1ab002bda43e23771cfeed28bbb77 to your computer and use it in GitHub Desktop.
Git Branch create and push new branches

> Create a new branch:

git checkout -b feature_branch_name

> Push your branch to the remote repository:

git push -u origin feature_branch_name

> To delete a local branch

git branch -d the_local_branch

> To remove a remote branch (if you know what you are doing!)

git push origin :the_remote_branch

> or simply use the new syntax

git push origin --delete the_remote_branch

> sync remote branches with local list

git fetch -p

> Clone a single branch

git clone -b <remote_repo>

Forked repository commands

> get remote addresses github

git remote -v

returns 
> origin  https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
> origin  https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)

> add upstream to sync code from original fork

git remote add upstream

returns 
> origin  https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
> origin  https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
> upstream  https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (fetch)
> upstream  https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (push)

Sync your fork regularly

> Fetch branches and their updated commits from master

git fetch upstream

> checkout your master branch

git checkout master

> Merge changes from upstream master to your master branch

git merge upstream/master

Rename a branch

> Rename branch

Change commit message -> make sure your in the correct branch

git commit --amend

check branch commits

git log

git push  <REMOTENAME> <LOCALBRANCHNAME>:<REMOTEBRANCHNAME> 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment