Git Status does not show 'ahead of' after edit and commit to local repo - git-status

Our company's workflow is to clone master branch into a _Test branch as we work on new features and we continually push/share this _Test branch until a set of features are complete and approved by client, then we merge to master branch and build and publish our sites. Then rinse and repeat.
The problem I'm having is git status isn't showing the correct ahead/behind (or more likely, I may not understand what it is supposed to show) while working on the _Test branch. If I do the following steps:
git checkout _Test
git pull --rebase origin _Test # get latest code
edit some files
get commit -am "Test commit"
git status
After step four, the git output is
[_Test d6fa824] Test commit
1 file changed, 1 insertion(+), 1 deletion(-)
Then after step five, the git output is
# On branch _Test
nothing to commit, working directory clean
Shouldn't it say?
Your branch is ahead of 'origin/_Test' by 1 commit.
If I look at qgit or gitk they show origin/_Test and remotes/origin/_Test respectively (correctly) 1 commit behind the last test commit. I'm running msysgit and git version outputs:
git version 1.8.1.mysysgit.1
So I'm confused why the output from git commit doesn't state that I'm ahead of origin/_Test (when obviously I am since I just committed) and why git status doesn't state same information.
Let me know if I need to provide any more info.

I resolved this problem.
You basically need to set up git tracking using
git branch --set-upstream *branch_name*
Read my full explanation here

Related

The local repository is out of date when push the code even after pull is completed

1.Pull the latest code[
2.Commit the new code
3. When tried to push the code to bitbucket repository getting message "Local repository out of date[![enter image description here]
**
tried bothway Xcode push and cmd based push but no luck still getting this weird message
Note:
Xcode 12.4,
bit bucket
I don't understand, the image shows after the "pull"? If not, please edit your question and place the image in the correct place.
That message can be because someone else have pushed to your repo after the last time you pulled from it. You will need to revert all the X commits that you have done after your last succed push (save the work in another branch or whatever):
git reset --hard HEAD~X
Or reset your local branch to directly match your remote branch:
git reset --hard origin/remote-branch-name
Pull from the repo, make your commits and then you will be able to push again.
You have another option: PULL FORCE!!!
If you alredy known the "push --force" command, then pull force will sound you familiar, but in reality doesn't exist something like "pull --force", but exist a way to replicate that functionality in pull requests:
git fetch --all
git reset --hard origin/master
git pull origin master
(Replace "master" by your branch name)
With that command you overwrite your git history to match exactly the history of your remote repository branch. That will overwrite local changes (the ones that you have not pushed yet) and then you can make your commits and push them.
You can avoid this ackward situation by always working in a new branch only for your work, and when you need to integrate your changes you can make rebase or merge.
There are changes in your local repository that are not on the remote and vice versa, causing a conflict in your history.
You could try the following in your local repository (assuming your remote is called origin):
Make sure your local changes are committed (git commit -am "Some commit message")
Create a new branch (git branch new-branch-name)
Fetch the remote branch (git fetch origin)
Reset the target branch to the version on the remote (git reset --hard origin/target-branch-name)
Merge your newly created branch (git merge new-branch-name)
Push your changes to the remote (git push origin target-branch-name)
Finally resolved it by push the commits to the new PR and then merged the code with old PR

Git-hub issue: Shows 87 files changed of my laravel project

I am new to git-hub and when I create a pull request it shows a large amount of file changed, I am working on Laravel5 and being a trainee in a company I have to send the PR to my team head. So, How to save a fresh Laravel file in master branch and then after doing 1 or 2 changes I commit and generate PR?
Showing 87 changed files with 834 additions and 2,357 deletions
First, if you generate a PR, do so from a dedicated branch, not from master.
Second, whenever you are pushing to a fork (to make a PR), rebase your local branch first on top of the original repo branch.
cd /path/to/local/repo
git remote add upstream /url/original/repo
git fetch upstream
git checkout mybranch # in your case, for now master
git rebase upstream/master # rebase on top of the destination branch
# which will receive and integrate your PR
git push --force origin mybranch
Then make your PR: the diff will be only your work, as opposed to a delta representing evolution on upstream done while you were preparing your fix.

Files committed do not appear after git commit, git stash, and git stash pop

I'm very new to this git thing, and as far as my experience goes, I've never encountered something like this before.
I've multiple local branches that I frequently switch around with, since I work with a group, and use other branches as a reference.
In this case, one of my friends committed and pushed something to his branch, and he suggested we have a look-see.
So I committed my changes on my own branch, but as usual, there are those Xcode files that magically edit themselves whenever we just open them, so I thought it would be a good idea to just git stash them (after the commit) and deal with them later, just so I can checkout my friend's branch and fetch the update.
After that was done, I switched back to my branch, and did git stash pop, and checked-out said files that aren't really important.
Then I noticed the files I created are gone.
I tried to do a git revert but it did nothing, not that I understood what happened, anyway.
Here's the list of commands I put in:
git add Integra-Geochemistry/Controllers/WaterSamplingFormOneViewController.swift
git add Integra-Geochemistry/Views/WaterSamplingFormOneView.swift
git add Integra-Geochemistry/Xibs/WaterSamplingFormOne.xib
git status
git commit -m "Initial commit - added WaterSamplingForm"
git status
git branch
git branch dev/surface-thermal-sampling
git checout dev/surface-thermal-sampling
git checkout dev/surface-thermal-sampling
git stash
git status
git checkout dev/surface-thermal-sampling
git pull origin dev/surface-thermal-sampling
git branch
git status
git branch
git checkout dev/watersampling
git status
git stash pop
git checkout Integra-Geochemistry/Xibs/AddRadonFormView.xib
git checkout Integra-Geochemistry/Xibs/RadonReadingFormFourView.xib
git checkout Integra-Geochemistry/Xibs/RadonReadingFormThreeView.xib
git checkout Integra-Geochemistry/Xibs/RadonReadingFormTwoView.xib
git checkout Integra-Geochemistry/Xibs/RadonReadingFormView.xib
git log
git revert 63947089d3479fff91ae4fb2ba5d59bd39d0c30d
For reference, here's the log file (after I did the git revert)
commit 8f5a3b8a4db5bad0a750ba08cd2d5b6a8a2fe18e
Author: <-------->
Date: Tue Jan 5 17:28:19 2016 +0800
Revert "Initial commit - added WaterSamplingForm"
This reverts commit 63947089d3479fff91ae4fb2ba5d59bd39d0c30d.
commit 63947089d3479fff91ae4fb2ba5d59bd39d0c30d
Author: <-------->
Date: Tue Jan 5 17:13:35 2016 +0800
Initial commit - added WaterSamplingForm
I've done a lot of committing, pushing and switching branches, but I never had anything disappear on me like this.
Is there any chance my files are okay and recoverable? I'd hate to start over. Thanks.
Is there any chance my files are okay and recoverable? I'd hate to start over. Thanks.
Yep.
type git reflog and checkout the desired commit that you want to get back to.
Basically every action you perform inside of Git where data is stored, you can find it inside of the reflog.
Git tries really hard not to lose your data, so if for some reason you think it has, chances are you can dig it out using git reflog.
What this means is that you can use it as a safety net: you shouldn’t be worried that a merge, rebase, or some other action will destroy your work since you can find it again using this command.
Read more about it here

Unable to update my GitHub from my Mac

Why am I unable to update my GitHub from my Mac?
git status produces the following:
On branch master Changes to be committed: (use "git reset HEAD
<file>..." to unstage)
new file: file.test
Untracked files: (use "git add <file>..." to include in what will be
committed)
.DS_Store
git push produces the following;
fatal: The current branch master has no upstream branch. To push the
current branch and set the remote as upstream, use
git push --set-upstream origin master
You need to git add ., then git commit -m "My commit message", then git push -u origin master.
That will set the upstream to the origin/master. Moving forward, just git push shall suffice
Git works through commits - which are basically snapshots of what your repository looked like at a given point in time. You need to commit the files to your repository before you can actually push them to GitHub.
So your first step is to add the files to the "Staging Area" with
git add file.text # you can do git add . but this will add all files which you may not always want
Now you can check the current status of the "Staging Area" with
git status
This will let you make sure that you are only committing the changes that you want added.
Now you can commit the changes. Committing will only 'save' the files that are in the Staging Area.
git commit -m "A useful description of what you did since your last commit"
Ok so now you're ready to push. Assuming you cloned from GitHub you can just run
git push origin master
But if you created this repository with git init you will need to tell git that you have a remote repository somewhere. Do this by running
git remote add https://github.com/<usernane>/<repo_name> origin
This origin is the name you would like to associate with the remote repository. 'Origin" is the most common but you may have other remotes like "backup" or "code_review" for different use cases.
Once you have added the remote repo, you can actually push to it with
git push origin master
Again, origin is the name for your remote repo and 'master' is a 'branch' name.
You can add the -u flag which will make it so that git assumes you want to push to origin. So in the future you would only need to run
git push
Listen to the error messages. :)
You currently have one untracked file, .DS_Store which I happen to know is a system file, so you may want to add that to your .gitignore
As for trying to push upstream, you need to set your upstream for each branch, so you simply need to type the command
$ git push --set-upstream origin master
then do a simple
$ git push
to send your changes to github.
If the branch you are pushing to online is ahead of you, then you may need to do a git pull to get grab the changes, before you do a git push.

Can't commit because someone else pushed, can't pull without discarding my changes in git

I am working with a friend on an iOS project, and we are using git for versioning, with Xcode. My friend has committed the changes, and I have my changes locally. When I try to commit my changes, I'm getting this error in Xcode:
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
When I try to pull, Xcode warns me about losing my local changes:
How can we simply merge the changes? I've used TFS before, and things were more much easy, we've checked in changes, and got latest, and if there was any conflict we could solve it. We don't need branching etc, we just need to keep our code in sync.
How can I solve this "deadlock" simply as possible? Or in other words, what is analogous to "just checking in/merging/getting latest in TFS" in git? Xcode built-in solutions preferred, without terminal.
UPDATE:
Here is what I get if I type git status at the terminal.
Cans-MacBook-Pro:myappname Can$ git status
On branch master
Your branch and 'origin/master' have diverged,
and have 1 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
You have unmerged paths.
(fix conflicts and run "git commit")
Changes to be committed:
modified: BigPostView.xib
modified: BigPostViewController.h
... (many others displayed here)
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: myappname/Storyboard.storyboard
Cans-MacBook-Pro:myappname Can$
You should always be able to commit your changes, since that's a local operation. You'll get an error only when you try to push your commited changes.
In order to push your commit, you'll have to pull your friend's changes first.

Resources