Git push to local repo says "everything up to date", it isn't - linux

I have a theme I use for our merchant store. I use git to maintain a repo (local repo 1) of this theme that i clone into a dev folder (local repo 2) and then work on there, when I'm done I want to update (push?) to the original local repo 1. From there I can render zip files or whatever I need for the merchant store.
So i made repo1 by git init and adding the files and committing it. worked fine. Then I cloned the repo to my dev folder and setup my web services there. Worked great. I edited my theme and made commits appropriately. Now that I am ready to put these changes on the live server I want to push to my origin which should be repo 1. However after making commits when I try to push from repo2 by
git checkout master
and then
git merge classes-migration
and then
git push
it says "everything up to date" I've tried specifying specifically the same branch to push, honestly I've tried all kinds of things reading through the different answers here.
git branch [for repo1]
classes-migration
import-classes-migration
initial-commit
* master
git status [for repo1]
On branch master
nothing to commit, working directory clean
git branch [for repo2]
classes-migration
* master
git status [for repo2]
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
git remote show origin [for repo2]
* remote origin
Fetch URL: /home/user/projects/merchant/repos/theme
Push URL: /home/user/projects/merchant/repos/theme
HEAD branch: master
Remote branches:
classes-migration tracked
import-classes-migration new (next fetch will store in remotes/origin)
initial-commit tracked
master tracked
Local branches configured for 'git pull':
classes-migration merges with remote classes-migration
master merges with remote master
Local refs configured for 'git push':
classes-migration pushes to classes-migration (up to date)
master pushes to master (up to date)
So.. yeah.

The push command is used to put in the server what you already has committed.
If you have a git repository configured, clone it in your dev machine, then work in this project. After that you need to commit your changes.
first check the status after the changes:
git status
If you get this message
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: filename.txt
no changes added to commit (use "git add" and/or "git commit -a")
It means you`ve changed the file filename.txt, if you've changed more then one file, every file will be listed here.
The next step is commit the file.
git commit filename.txt -m "commit comments"
Just after that, you push to the server:
git push
After this command, when you clone in another machine or update the repository the user will see the modifications.

Related

"error: pathspec 'master' did not match any file(s) known to git" when trying to switch to master branch

I'm getting the following error message when trying to switch to the master branch.
[root#testlab testing_repo]# git checkout master
error: pathspec 'master' did not match any file(s) known to git
Here are the steps I followed:
I created a master branch with name "testing_repo"
and converted this directory to repository with git init testing_repo.
I created 3 files using touch file1 file2 file3
in testing_repo.
[root#testlab testing_repo]# ls
file1 file2 file3
these 3 files I have staged.
I created a new branch with git checkout -b feat/add_git_tutorial.
I added a new file git_tut.txt which i
staged and commited using git add and git commit -m "message".
[root#testlab testing_repo]# ls
file1 file2 file3 git_tut.txt
I tried to switch to master branch using git checkout master
but I get an error:
[root#testlab testing_repo]# git checkout master
error: pathspec 'master' did not match any file(s) known to git
You do not have a branch named "master"
The error
error: pathspec 'master' did not match any file(s) known to git
is exactly the error you get if you try to check out a commit reference that does not exist, be it a branch name, tag name or commit hash. The wording of the message is misleading to people not familiar with the inner workings of git.
To see the list of branches in your repo:
git branch
I'll bet you won't see "master" in the output. There are two possibilities for why you don't have a "master" branch.
Possibility #1: You switched branches before your first commit.
The default branch (usually "master" or "main", see next section) isn't created when you init the repo, but when you make your initial commit. If you switch branches before that initial commit, the default branch ("master") is never created.
In your step 2 you created and staged some files. But then in your step 3 you switched branches before every committing those staged changes. So the default branch (e.g. "master") was not created. If you redo your above steps, but do a git commit before step 3, you should get a message that that files were committed to "master" (assuming that's your default branch, see below).
Possibility #2: Your git is configured to use another default branch name for new repos.
It is possible your git installation is configured to initialize new repos with "main" or some other name instead of "master".
ℹ️ If you want to understand the background behind switching from "master" to "main", read Regarding Git and Branch Naming/
You can check what your installation's "default default" branch with:
git var GIT_DEFAULT_BRANCH
If you want to change the "default default" branch name for new repos, the easiest way is with:
git config --global init.defaultBranch <your_name_pref_here>
If you want to rename the default branch of an existing repo, say from "main" to "master":
git branch -m main master

Error in Github when I do "git push origin master" (error: src refspec master does not match any)

My branch in the Github repository is "master". In the terminal I did:
git branch
and the output is:
* main
my-temporary-work
I wanted to push a file to Github and I used:
git add exploratory_analysis.ipynb
git commit -m "New version"
git push origin master
The "git add" and "git commit" commands work. However, the last command (i.e., "git push origin master") does not work, and I get this error:
error: src refspec master does not match any
error: failed to push some refs to 'git#github.com:NAME-OF-USER/REPOSITORY-NAME.git'
That is, it looks like I cannot push any code from my laptop to Github. How can I fix it?
I faced the same issue some days ago.
If you created a new repository nowadays(2020) then the default branch in main on GitHub.
you can check on GitHub now in your repository branches.
so that's why you need to run
git push origin main
instead of
git push origin master
Goodluck with more details you can watch video
Why are you pushing to master if the branch commands outputs main? Try 'git push origin main'
Also found this explanation for the change:
https://stackoverflow.com/a/65008828/1959534

can't push to gitlab, failed and rejected

has been pulled, the result is still an error ! [rejected] dev->dev(non-fast-forward)
D:\PPI_Roketin\Project\astrowatch (dev)
λ git add resources/views/reals/_form.blade.php
D:\PPI_Roketin\Project\astrowatch (dev)
λ git commit -m "resources/views/reals/_form.blade.php"
[dev db5ac99] resources/views/reals/_form.blade.php
1 file changed, 2 insertions(+), 2 deletions(-)
D:\PPI_Roketin\Project\astrowatch (dev)
λ git push origin dev
To gitlab.com:roketin-stellar/astrowatch.git
! [rejected] dev -> dev (non-fast-forward)
error: failed to push some refs to 'git#gitlab.com:roketin- stellar/astrowatch.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
error like this, why?
have done git checkout, and repeated the command, it's still an error like above
This is a classic git error. The problem is described in the error message: Updates were rejected because the tip of your current branch is behind, which means that there have been changes to the remote branch that you do not have locally. There are quite a few ways to fix this, one of which is also described in the git message: Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again.
If you do git pull origin dev this will merge whatever changes are made in the remote to your local branch. Once you fix the merge conflicts, you can then push the branch.
Another option would be to run a rebase by performing git pull --rebase origin dev, which will bring in the remote changes and rebase your commits on top of the remote commits. This will result in a cleaner git history.
The easiest for now would probably just doing a git pull, then once it's merged correctly, pushing to your remote.
I definitely recommend researching the git commands and learning how to find the resources correctly in the docs. There is a lot available online.
you can try git reset --hard HEAD
please remind that:
HEAD points to your current branch (or current commit), so all that git reset --hard HEAD will do is to throw away any uncommitted changes you have.
It's quite self explanatory, you need to keep yourself upto date with remote branch if you want to commit and it looks like git pull will overwrite files you've made changes to. You should commit your changes first.

How to pull from specific branch in git- understanding gap

I am using gitlab and really confused in few things. :
When we create new branch by git checkout -b test. Does it create copy of master or it creates copy of branch i am currently in?
For example: I am currently at branch dev, then i write command git checkout -b test. So it will be copy of dev, not masters?
Pull : when we write git pull , it pulls changes of current branch from remote branch of same name. Its used when more people are working on same project.
Example : I am at branch dev, i write git pull, it updates my local as of dev in remote. Now i created a new branch test, checkout test branch and do git pull. It gives me :There is no tracking information for the current branch.
Please specify which branch you want to rebase against.
its because there is no test branch in remote ?
What command to be used if i want to pull from dev branch while my current branch is test? is it git pull --rebase dev test?
When we write git push, it pushes current branch to remote one.
example : i am on branch test, i add, commit and write git push. It simply pushes my branch test to remote with same name as test.
Can we push to specific branch like push test to dev?
What is difference in following considering i am at branch test:
git push
git push origin test
they both push to remote?
My requirement is : there is branch dev which is not master branch, i am supposed to work on this branch as starting and end point. Like, new branch should be copy of this and i am supposed to push to same branch.
Does it create copy of master or it creates copy of branch i am currently in?
It creates a new branch named test based on the current branch, whatever that might be, as a starting point.
What command to be used if i want to pull from dev branch while my current branch is test?
I believe you can pull any branch you wish into your current branch. E.g. if you were on branch test and wanted to pull dev you could just use:
git pull origin dev
Can we push to specific branch like push test to dev?
Yes, can specify both the local and remote branch names when pushing, e.g.
git push origin test:dev
1- When you do git checkout -b test it creates copy of your current branch(in this case 'dev').
2- git pull will only sync your changes between remote and local. If you upload the branch and try to pull, it does not work because your local and remote changes will be synchronized.
3- This could help you : Make an existing Git branch track a remote branch?.
If you want to work in a copy of a branch, you should do this:
git checkout <origin_branch> (master, dev, what u want )
git checkout -b <work_branch> (test, for example. This create a copy of your origin branch)
After this, you have a new branch 'test' in your local repository. If you want to push this branch on the repo:
git add .
git commit -m "Pushing new branch test"
git --set-upstream origin <your_new_branch>

remote git repo cannot be auto checkout after a merge hook

I have a remote non-bare git repo, which is my static blog site.
I push a commit in local master branch to the remote master branch every time, and there is a post-update hook, which is like below:
echo "hook..."
git merge master
echo "after hook..."
In the remote repo, there is a pages branch which is checked out by default, what I want is that pages branch keep update of the master branch and auto checkout to workspace.
However, workspace cannot be checkout automatically, but the two branch has been updated.
In sum, What I want is the workspace can update after the pages branch merged every time. So that my website can update too.
==========detail process===========
==local repo:
*master
==remote repo:
*pages
master
git push local-master ---> remote-master [OK]
trigger hook do : git merge master to pages branch (which is checked out) [OK]
workspace updated (this is what I want) [NOT-OK]
Considering the current working directory of such an hook is the .git/ folder itself (ie, GIT_DIR is set to '.', which in non-bare repo is .git/), try a .git/hooks/post-receive with:
unset GIT_DIR
cd ..
git merge master

Resources