Languages
[Edit]
EN

Git - how push local changes into new branch?

13 points
Created by:
Veer-Ahmad
487

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:

1. Branch creation steps

Edit

1.1. (Optionally) Check changes and list all branches

Edit

Run command:

Output: 

Note: readme.txt file has been found with available only master branch (git branch -a returned nothing).

1.2. Create new brach:

Edit

Run command:

Output:

1.3. (Optionally) Check active branch and changes:

Edit

Run command:

Output:

Note: active brunch name is my_new_brach_with_local_changes with listed changed/added files.

1.4. Add, commit and push changes:

Edit

Run commands:

Output: 

Run command:

 Output:

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 just git push is needed to send changes. origin describes default remote repository saved inside .git/config file.

1.5. (Optionally) Check active branch and changes:

Edit

Run command:

Output:

 Run command:

Output:

 Note: to switch branch to master git checkout master should be used.

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Git

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join