Skip to content

Instantly share code, notes, and snippets.

@RazaChohan
Last active May 15, 2019 16:35
Show Gist options
  • Save RazaChohan/4359ec1e740e133cd35c to your computer and use it in GitHub Desktop.
Save RazaChohan/4359ec1e740e133cd35c to your computer and use it in GitHub Desktop.

Fetch all branches :

$ git branch -r | grep -v HEAD | awk -F'/' '{print $2 " " $1"/"$2}' | xargs -L 1 git branch -f --track 
$ git fetch --all 
$ git pull --all 
$ git checkout -b [name_of_your_new_branch]

Push the branch on github :

$ git push origin [name_of_your_new_branch]

When you want to commit something in your branch, be sure to be in your branch.

You can see all branches created by using :

$ git branch

Add a new remote for your branch :

$ git remote add [name_of_your_remote] 

Push changes from your commit into your branch :

$ git push origin [name_of_your_remote]

Update your branch when the original branch from official repository has been updated :

$ git fetch [name_of_your_remote]

Then you need to apply to merge changes, if your branch is derivated from develop you need to do :

$ git merge [name_of_your_remote]/develop

Delete a branch on your local filesystem :

$ git branch -d [name_of_your_new_branch]

To force the deletion of local branch on your filesystem :

$ git branch -D [name_of_your_new_branch]

Delete the branch on github :

$ git push origin :[name_of_your_new_branch]

Ignore all present untracked files :

$ git status -u no

Git merge strategy for specific files (“ours”, “mine”, “theirs”) :

$ git checkout --ours -- (paths)

or

git checkout --theirs -- (paths)

Delete all branches already merged:

git push origin --delete $(git branch -r --merged origin/master |  grep origin | egrep -v '>|master|develop' | cut -d/ -f2-)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment