Using Git sometimes it is necessary to make new branch after local changes has been made. In this article simple solution how to push changes into new branch has been described.
1. Branch creation steps
1.1. (Optionally) Check changes and list all branches:
$ git status On branch master No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) readme.txt nothing added to commit but untracked files present (use "git add" to track) $ git branch -a
readme.txtfile has been found with available only
git branch -areturned nothing).
1.2. Create new brach:
$ git checkout -b "my_new_brach_with_changes" Switched to a new branch 'my_new_brach_with_changes'
1.3. (Optionally) Check active branch and changes:
$ git status On branch my_new_brach_with_changes No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) readme.txt nothing added to commit but untracked files present (use "git add" to track)
Note: active brunch name is
my_new_brach_with_changeswith listed changed/added files.
1.4. Add, commit and push changes:
$ git add -A $ git commit -m "My first commmit to my new branch" [my_new_brach_with_changes (root-commit) 5e87717] My first commmit to my new branch 1 file changed, 1 insertion(+) create mode 100644 readme.txt $ git push --set-upstream origin my_new_brach_with_changes Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Writing objects: 100% (3/3), 240 bytes | 120.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To C:/Users/qurek/Desktop/git test/TestRepository.git/ * [new branch] my_new_brach_with_changes -> my_new_brach_with_changes Branch 'my_new_brach_with_changes' set up to track remote branch 'my_new_brach_with_changes' from 'origin'.
git add -Aadded all created/changed files to list to send,
git commit -m "My first commmit to my new branch"sent added files to local repository (
git push --set-upstream origin my_new_brach_with_changescreated remote repository with same name (
my_new_brach_with_changes) and sent local repository changes into remote one.
--set-upstreamset up remote reposotory where in future all local changes will be send - next time just
git pushis needed to send changes.
origindescribes default remote repository saved inside
1.5. (Optionally) Check active branch and changes:
$ git branch -a master * my_new_brach_with_changes remotes/origin/my_new_brach_with_changes $ git status On branch my_new_brach_with_changes Your branch is up to date with 'origin/my_new_brach_with_changes'. nothing to commit, working tree clean
Note: to switch branch to master
git checkout mastershould be used.