Git - ErikStaats/Notes GitHub Wiki
- Create a new branch with git and manage branches
- How do I delete a Git branch both locally and remotely?
To create a branch, use "git checkout -b
" to create it locally and
"git push -u
" to push it to the remote with upstream (tracking) references.
Edee$ git checkout -b my_branch
Switched to a new branch 'my_branch'
Edee$ git push -u origin my_branch
Counting objects: 6, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (6/6), 1.29 KiB | 662.00 KiB/s, done.
Total 6 (delta 0), reused 0 (delta 0)
remote:
remote: Create a pull request for 'my_branch' on GitHub by visiting:
remote: https://github.com/ErikStaats/Test/pull/new/my_branch
remote:
To https://github.com/ErikStaats/Test.git
* [new branch] my_branch -> my_branch
Branch 'my_branch' set up to track remote branch 'my_branch' from 'origin'.
Edee$
Before deleting a branch, make sure you're not in the branch being deleted. In
this example, we switch to the "master
" branch.
Use "git branch -d
" to delete the branch locally and "git push --delete
" to
delete the branch on the remote.
Edee$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
Edee$ git branch -d my_branch
Deleted branch my_branch (was ecb5d62).
Edee$ git push --delete origin my_branch
To https://github.com/ErikStaats/Test.git
- [deleted] my_branch
Edee$
To display local git info like branch and remote mappings, look in the file "'.git/config'".
Edee$ cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = https://github.com/ErikStaats/Test.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
Edee$