There are three branches named 'dev1', 'dev2' and 'main'. I am working on 'dev2' branch and my friend is working on 'dev1' branch. We both are fetching and uploading our code from 'main' branch. ('main' branch is the ultimate branch)
Now, suppose I made some changes locally in my 'dev2' branch. Now, I want to push those changes to 'dev2' branch. But, before that, my friend has pushed some changes from'dev1' to 'main' branch. So what should I do?
Please show me step-wise commands for github
for e.g.
step1: git <---do something--> step2: git <--do something 2--->
Hello, I will gladly answer your question.
First, you work in local the steps is more similarity in windows that Linux and other steps in
When you are located in your directory, you need to have the branches created, to make sure you have the branches you can do a
git branch
and quit with "q" key
It is also important to check that you have your repository created, and connected to your repository
git remote -v
If not, add your repository, either with HTTPS, or SSH.
git remote add origin https://github.com/user/repositoryexample.git
Here are the step-wise commands you can use to push your changes to the dev2 branch while ensuring that you have the latest changes from your friend's dev1 branch, which have been merged into the main branch.
Ensure that you are on the dev2 branch by running the command in your local repository:
git checkout dev2
Next, fetch the latest changes from the main branch by running command:
git fetch origin main
Merge the changes from main branch into your dev2 branch, running the next command:
git merge origin/main
Now that your dev2 branch is up to date with the latest changes from main, you can push your changes to the remote dev2 branch by running the following command:
git push origin dev2
This will push your changes to the dev2 branch on the remote repository.
Note: If there are conflicts between your changes and the changes from dev1 branch, Git will prompt you to resolve them before you can complete the merge. In this case, you will need to resolve the conflicts manually before you can push your changes.
Also, you can just push your dev2 branch and on GitHub you can work with the Codespace.
git checkout dev2
git push origin dev2
When you have these steps, you would be interested to know how to update your branches from GitHub and manage your branches.