EN
Git - how push local changes into new branch?
13 points
Using Git sometimes it is necessary to make new branch for locally changed files. In this article we want to show how to do it.
Quick solutuion:
xxxxxxxxxx
1
git checkout -b "my_new_brach_with_local_changes"
2
git add -A
3
git commit -m "My first commmit to my new branch"
4
git push --set-upstream origin "my_new_brach_with_local_changes"
Run command:
xxxxxxxxxx
1
git status
Output:
xxxxxxxxxx
1
On branch master
2
3
No commits yet
4
5
Untracked files:
6
(use "git add <file>..." to include in what will be committed)
7
8
readme.txt
9
10
nothing added to commit but untracked files present (use "git add" to track)
Note:
readme.txt
file has been found with available onlymaster
branch (git branch -a
returned nothing).
Run command:
xxxxxxxxxx
1
git checkout -b "my_new_brach_with_local_changes"
Output:
xxxxxxxxxx
1
Switched to a new branch 'my_new_brach_with_local_changes'
Run command:
xxxxxxxxxx
1
git status
Output:
xxxxxxxxxx
1
On branch my_new_brach_with_local_changes
2
3
No commits yet
4
5
Untracked files:
6
(use "git add <file>..." to include in what will be committed)
7
8
readme.txt
9
10
nothing added to commit but untracked files present (use "git add" to track)
Note: active brunch name is
my_new_brach_with_local_changes
with listed changed/added files.
Run commands:
xxxxxxxxxx
1
git add -A
xxxxxxxxxx
1
git commit -m "My first commmit to my new branch"
Output:
xxxxxxxxxx
1
[my_new_brach_with_local_changes (root-commit) 5e87717] My first commmit to my new branch
2
1 file changed, 1 insertion(+)
3
create mode 100644 readme.txt
Run command:
xxxxxxxxxx
1
git push --set-upstream origin my_new_brach_with_local_changes
Output:
xxxxxxxxxx
1
Enumerating objects: 3, done.
2
Counting objects: 100% (3/3), done.
3
Writing objects: 100% (3/3), 240 bytes | 120.00 KiB/s, done.
4
Total 3 (delta 0), reused 0 (delta 0)
5
To C:/Users/qurek/Desktop/git test/TestRepository.git/
6
* [new branch] my_new_brach_with_changes -> my_new_brach_with_changes
7
Branch 'my_new_brach_with_changes' set up to track remote branch 'my_new_brach_with_changes' from 'origin'.
Notes:
git add -A
added all created/changed files to list to send,git commit -m "My first commmit to my new branch"
sent added files to local repository (my_new_brach_with_changes
),git push --set-upstream origin my_new_brach_with_changes
created remote repository with same name (my_new_brach_with_changes
) and sent local repository changes into remote one.--set-upstream
set up remote reposotory where in future all local changes will be send - next time justgit push
is needed to send changes.origin
describes default remote repository saved inside.git/config
file.
Run command:
xxxxxxxxxx
1
git branch -a
Output:
xxxxxxxxxx
1
master
2
* my_new_brach_with_changes
3
remotes/origin/my_new_brach_with_local_changes
Run command:
xxxxxxxxxx
1
git status
Output:
xxxxxxxxxx
1
On branch my_new_brach_with_changes
2
Your branch is up to date with 'origin/my_new_brach_with_changes'.
3
4
nothing to commit, working tree clean
Note: to switch branch to master
git checkout master
should be used.