GitHub Failed to sync this branch - github

IM getting this error message that says syncing has failed. I looked around for solutions and found that git status would give some idea about the problem. So I did it and got this:
# On branch dev_0.9_HUD_development
# Your branch is behind 'origin/dev_0.9_HUD_development' by 1 commit, and can be
fast-forwarded.
# (use "git pull" to update your local branch)
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: res/models/hud/HUD2.png
# modified: src/Weapon/Laser.java
# modified: src/Weapon/Weapon.java
# modified: src/game/world/gui/hud/HeadsUpDisplay.java
# modified: src/game/world/gui/hud/ShipStat.java
# modified: src/game/world/gui/hud/WeaponDisplay.java
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# src/hero101.mtl
# src/hero101.obj
There were many solutions but none of them seem to work. I tried restarting computer. Nothing happened. I tried git checkout but it gives another error. I tried merging the branches still get the same error. What can I do to fix this?

If your branch is behind an upstream remote branch, that means you haven't done any commit.
In command line:
cd /patH/to/your/repo
git stash
git pull
git stash pop
git add -A
git commit -m "My work"
git push
That assumes that all the files listed by your current git status are modified files that you want to version.

Ok. So i looked into the .git folder in the repo. I changed the name of index.lock file, after that i did the git stash and git pull and everything worked.

Related

resolve error : "commit your changes or stash them before you can switch branches"?

I was on master branch which had following files in staging area :
modified: app/assets/stylesheets/login.css
modified: app/controllers/application_controller.rb
modified: app/controllers/users_controller.rb
modified: app/views/users/forgot.html.erb
modified: app/views/users/new.html.erb
new file: app/views/users/new_password.html.erb
modified: config/routes.rb
As I wished to pull the latest commits, I stashed these files using
"git stash"
, did a
"git pull"
. Then I moved to my local branch "password_change" and did a
"git stash pop".
Now i have above mentioned files in my local branch.
When i tried going back to master branch, it gave the following error :
error: Your local changes to the following files would be overwritten by checkout:
app/controllers/application_controller.rb
Please, commit your changes or stash them before you can switch branches.
Aborting
I wish to keep these files only in my local branch i.e. "password_change" and move to master branch. How should I overcome the error? Please help me as I am new to github.

git is not ignoring an eclipse .version file

It may be something simple, but I cannot make git ignore this. I have put different combinations of things into the .gitignore file in the directory at the root of my repository.
But I still see:
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: .gitignore
modified: MyProject/build/.version
no changes added to commit (use "git add" and/or "git commit -a")
$
I have "build" in my .gitignore file. I have tried "MyProject/build/.version", "build/.version", ".version" and various combinations thereof. But perhaps not the right combination.
If you've only just added build to your .gitignore, then the files which were tracked before will still be tracked. .gitignore only prevents git from tracking new, untracked files which match the pattern given. To remove the file from git's history, without removing the file locally, you can run
git rm -r --cached build
to remove everything in the build directory, or
git rm --cached MyProject/build/.version
(or whatever the path is) to just remove the one file.
Try entering the following in your .gitignore:
/build
Another thing to try is
build/

Git push - everything is up to date?

Git newbie here - Ive setup a git repository which was working and have pushed a few commits. I made a code change now and am trying to push the new updates but I keep getting:
I did a:
git commit -m "message"
Then:
git push origin master
Everything up-to-date
Not sure where I have gone wrong.
git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: Makefile
# modified: weather-station
# modified: weather-station.c
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .gitignore
If I have a look at the code on github its old and the changes have not been sync'd.
Any idea where i went wrong or how I can fix this?

How to sync unsynced commits?

I committed a change in my file and want to sync it. I am using the Windows Github user interface and I am new to this. The sync button does not show up. How can I do this with a shell command?
If you look at the screenshot, near the top it says detached head. Although rather unpleasant sounding, this just means that you're not on a branch but rather having a commit checked out.
Looking at one of your comments, it says rebasing master. Looks to me like a rebase was started, but never finished. If you haven't touched the command line, this sounds like a bug in GitHub for Windows, and I'd report it to GitHub support. It should still be possible to clean this up though.
If you type git status in the command line, you should get something like this (this is on Linux, it may look slightly different on Windows):
[~/dev/cost_model] git status
# Not currently on any branch.
# You are currently rebasing branch 'master' on '174ffcb'.
# (fix conflicts and then run "git rebase --continue")
# (use "git rebase --skip" to skip this patch)
# (use "git rebase --abort" to check out the original branch)
#
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: some/path/to/a/file
#
# Unmerged paths:
# (use "git reset HEAD <file>..." to unstage)
# (use "git add <file>..." to mark resolution)
#
# both modified: some/other/path/to/a/file
#
The files under "Changes to be committed" are fine, and were rebased just fine. If you have any files under "unmerged paths", though, you should open them and check for merge conflicts (they are sections of the code that begin with "<<<<<<<" or something similar, just open the file and make sure the file ends up looking like you want it to).
Once you've resolved all conflicts, run git rebase --continue. Check the message that appears, there may still be conflicts.
Another option is to run git rebase --abort to stop the rebase if you didn't want it to finish.
Once you're done, you should be back on your branch and be able to sync.
Try: git push origin {branch_name}

How to use Git for updating my directory and other contents?

I have a directory like below:
/var/tmp/main
.. plugin1
.... mysource.c
.. plugin2
.... mysource.c
.. plugin3
.... mysource.c
And I created a repository. After that, I applied the below:
$ cd /var/tmp/main
$ git init
$ echo "hello git plz work" >> README
$ git add README
$ git commit -m 'first commit works'
$ git remote add origin git#...../main.git
$ git push origin master
I also tried
$ git add .
$ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
# (commit or discard the untracked or modified content in submodules)
#
# modified: folder1 (modified content)
# modified: folder2 (modified content)
# modified: folder3 (modified content)
# modified: folder4 (modified content)
# modified: folder5 (modified content)
# modified: folder6 (modified content, untracked content)
# modified: folder7 (modified content)
# modified: library (modified content, untracked content)
#
no changes added to commit (use "git add" and/or "git commit -a")
$ git commit -m 'Suggested by Stack experts'
$ git push
Tried also .gitignore
$ cat .gitignore
*.[oa]
*.pyc
*.gcda
*.gcno
*.la
*.lo
*.loT
*.sw[po]
*.tar.*
*~
.deps
.libs
ABOUT-NLS
INSTALL
Makefile
Makefile.in
aclocal.m4
autom4te.cache
autoregen.sh
compile
config.guess
config.h
config.h.in
config.log
config.rpath
config.status
config.sub
configure
depcomp
install-sh
libtool
ltmain.sh
missing
stamp-h1
Same so far...
All set but after 14 hours I still do not see all of my directories in Git, I only see the README file showing.
How can I commit all? (following http://scottr.org/presentations/git-in-5-minutes/ )
Here is the simple method to add empty directories:
//create some empty, gitignore files.
touch ./someDir/.gitignore
touch ./someOtherDir/.gitignore
...etc..
git add ./someDir/.gitignore
git add ./someOtherDir/.gitignore
...etc...
git commit -am " Add empty project directories."
This is because, as mentioned in other answers git tracks files in directories, but ignores directories on their own. This also might be fixed/solved in the git add mechanism in more up to date versions (I vaguely remember them adding their own .gitignore files to empty directories), so I'd really recommend trying to upgrade to the highest git version you can for that and other benefites, your distro may provide by default an older version, as ubuntu and debian do.
Edit:
The above technique is designed for the minimal amount of disturbance of your working directories in order to get empty folders tracked. -Each- directory would in my examples get their own .gitignore file (you can have as many .gitignore files as you like, they are additive).
So at the end your folder structure would look like this:
/var/tmp/main
.. plugin1
.... mysource.c
.... .gitignore
.. plugin2
.... mysource.c
.... .gitignore
.. plugin3
.... mysource.c
.... .gitignore
And then you would add the .gitignore files as placeholders!
But let's take a step back and try the opposite tactic:
Maximum visibility.
Go to any folder you want to add, e.g. plugin1 . Create a file in that folder, call it placeholder.
Now navigate to that folder from the command line, e.g. cd /var/tmp/main/plugin1/ and git add that placeholder file, e.g. git add placeholder . You've told git that you want that file tracked (if you type git diff you can review the "proposed" changes. It'll tell you that it sees the file, but that it's just an empty file, which is fine).
Now commit the file: git commit placeholder -m " Adding a Placeholder file."
When you add any file, all the folders that contain that file, down to the main git folder, get added as well, so you'll now have /plugin1/ tracked in git.
Go through, use git add /path/to/file on any of those (?) c source files you have, and then commit the changes, via git commit /path/to/file. Generally, anything that's pure text, it's good to be added to the repository, of course.
Finally: Be aware that git status is only designed to tell you about modified, tracked files, including newly added files. If there are no modifications, it'll just give you mostly blank output.
To see the files that -are- actually tracked by git, use git ls-tree HEAD which will only show you tracked files!
For a clean start
Here is how I generally start a git repository.
cd /path/to/project/
git init
echo "README" >> README
git add .
git commit -am " Initial Commit of readme and files."
You only added your README file. If you type git status, you will see that all of your other files are considered "untracked". You need to add them with git add so they will be tracked:
git add file1 file2 file3
git commit -m 'Added remaining files to repository'
git push
The important point about "git add ." is that it looks at the working tree and adds all those paths to the staged changes if they are either changed or are new and not ignored
And neither Git or Mercurial track empty dirs