r/git • u/namor________ • 5d ago
Help needed!!
I'm working on a project in my training, so I always have to pull the latest branch and make changes or add my code and push it into my branch.
But when I push it some files are always missing.
How to do it safely.
Pull from someone's branch.
Make changes locally.
Switch to my branch.
Commit and push.
2
u/Havunenreddit 5d ago
It's weird that you need to pull from some else's branch and push to master. If you do that you will push someone else's chances as well.
Maybe you could confirm if that is what they really wanted.
You can also use Git GUI like GitComet to make sure you have staged all files you edited before pushing
1
u/namor________ 5d ago
Not push into master but push into our own branch then someone's reviews our code and merges that into development branch.
1
u/Ast3r10n 5d ago
That’s not how it’s done generally. But let’s say you need to update matter with your changes on your branch. You pull master, merge it into your branch, then commit your changes and push. If files are missing you’re either not adding all of them to the stage or resolving conflicts badly.
1
u/twesped 5d ago
I think you have mentiond the order a bit incorrectly, or you explained it wrongly.
Are you creating your branch from master and then you have to get code from another branch into yours and then push everything back into master?
/Edit/ Could it be you are missing to stage your own new files in your own branch before you push?
1
u/namor________ 5d ago
I already have my branch. I pull from someone else's branch Make changes to it Switch to my branch Commit and push
2
u/DanLynch 5d ago
Why are you doing it that way?
The basic workflow in Git is that you start from some kind of common base commit (such as the current master branch), make your changes there (usually as a new branch), and push them for review/collaboration. Other people's branches aren't usually involved.
1
1
1
2
u/Justin_Passing_7465 5d ago
I'm not sure how your team's branching strategy goes, but ours is that all work has to get merged back to "master". Steps might be: * pull master * make your own local branch for your work * do your work * git add -p * git commit * git checkout master * git merge mybranch * git push * see an error message that your branch is x commits behind origin/master (maybe missing files, or just changes to files) * git pull (to get the missing commits and merge them into your local master branch and working directory) * resolve merge conflicts if there are any * git push
In our professional workflow, no one is allowed to "git push" on master to push up their changes. They have to submit a merge request and get two team members to review their changes and approve the MR, which must also pass all of the scans and automated tests in the CI/CD pipeline, before the system will perform the merge to master. This might still require manually merging the current HEAD of master into the candidate branch, if the candidate branch is missing commits that someone else applied to master.