Showing posts with label GitHub. Show all posts
Showing posts with label GitHub. Show all posts

Git errors: cannot checkout branch - error: pathspec 'branch_name' did not match any file(s) known to git

 git checkout branch_name

error: pathspec 'branch_name' did not match any file(s) known to git

To fix that you can remove remote origin and link it again.

First, check the remote origin:

git remote -v
origin  git@github.com:company/project_name (fetch)
origin  git@github.com:company/project_name (push)


Then remove origin:

git remote remove origin


And add remote origin again with correct path from your repository (copy from

GitHub/GitLab/etc.):

git remote add origin git@github.com:company/project_name.git


After that run:

git pull --ff-only


And set upstream to origin branch:

git branch --set-upstream-to=origin/current_branch


Steps:

1. git remote -v
2. git remote remove origin
3. git remote add origin git@github.com:company/project_name.git
4. git pull --ff-only
5. git branch --set-upstream-to=origin/current_branch


Git fetch is not fetching all branches. error: pathspec did not match any file(s) known to git.

The problem can be seen when checking the remote.origin.fetch setting
(The lines starting with $ are bash prompts with the commands I typed. The other lines are the resulting output)
$ git config --get remote.origin.fetch
+refs/heads/master:refs/remotes/origin/master
As you can see, in my case, the remote was set to fetch the master branch specifically and only. I fixed it as per below, including the second command to check the results.
$ git config --replace-all remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
$ git config --get remote.origin.fetch
+refs/heads/*:refs/remotes/origin/*
The wildcard * of course means everything under that path.

Merge remote repo into forked repo

1. Add the remote, call it “upstream”:

git remote add upstream https://github.com/whoever/whatever.git

2. Fetch all the branches of that remote into remote-tracking branches,
such as upstream/master:

git fetch upstream

3. Make sure that you’re on your master branch:

git checkout master

4. Rewrite your master branch so that any commits of yours that aren’t already in upstream/master are replayed on top of that other branch:

git rebase upstream/master

5. Push to your remote fork

git push -f origin master

Adding an existing or new project to GitHub using the command line

  1. Create a new repository on GitHub. To avoid errors, do not initialize the new repository with README, license, or gitignore files. You can add these files after your project has been pushed to GitHub.
  2. Open Terminal.
  3. Change the current working directory to your local project.
  4. Initialize the local directory as a Git repository.
    git init
    
  5. Add the files in your new local repository. This stages them for the first commit.
    git add .
    # Adds the files in the local repository and stages them for commit. To unstage a file, use 'git reset HEAD YOUR-FILE'.
    
  6. Commit the files that you've staged in your local repository.
    git commit -m "First commit"
    # Commits the tracked changes and prepares them to be pushed to a remote repository. To remove this commit and modify the file, use 'git reset --soft HEAD~1' and commit and add the file again.
    
  7. Copy remote repository URL fieldAt the top of your GitHub repository's Quick Setup page, click  to copy the remote repository URL.
  8. In Terminal, add the URL for the remote repository where your local repository will be pushed.
    git remote add origin remote repository URL
    # Sets the new remote
    git remote -v
    # Verifies the new remote URL
    
  9. Push the changes in your local repository to GitHub.
    git push -u origin master
    # Pushes the changes in your local repository up to the remote repository you specified as the origin

Git + How to apply diff file to current Git branch

>> patch -p1 < a.diff

Git + How to do or get the cherry-pick without commit

>> git cherry-pick -n <commit>

>> git log

Git + How to merge git one branch to another without commit

>> git branch

>> git merge new_branch --squash

Git + How to get diffrence or diff of already added files or new files

Get difference of files

 >> git diff

Get difference of already added files

>> git diff --cached

Get difference of new files

>> git add -N new.txt

>> git diff

Git + Push local code or files to remote master branch

>> git branch

>> git status

>> git push origin <branchname>

Git + How to commit added files or files to git

>> git status

>> git commit -m “comment”

Git + How to add a file to git

>> git add <filename>


>> git status

Git + How to view or get difference of already added git files

Difference of already added files

>> git diff --cached

Git + How to find diffrence between current git local branch to master

Difference between current branch and master

>> git branch

>> git diff --name-status master..another_local_branch

Git + How to get or view all remote branches of a author or by an author


function gbl() {

git for-each-ref --sort=-committerdate --format='%(committerdate) %(authorname) %(refname)' refs/remotes/origin/|grep -e ".$@"|head -n 10;

}

Add the above function to bash_profile / profile. And then you can call like, >> gbl author


>> vim ~/.profile

add the following line,

function gbl() { git for-each-ref --sort=-committerdate --format='%(committerdate) %(authorname) %(refname)' refs/remotes/origin/|grep -e ".$@"|head -n 10; }


then call it like below,

>> gbl author_name


Git + How to remove a remote git branch

>> git branch

>> git push origin :the_remote_branch

Git + How to remove a local git branch from my machine

>> git branch

>> git branch -d the_local_branch

Active Directory Connection using LDAP and Java


My first project on GitHub. Happy :-)

Active directory Synchronization using LDAP protocol with JAVA

You can download the code from the repository:

https://github.com/complanboy2/Active-Directory-Synch-Ldap

Mail me for any queries: complanboy2@gmail.com
Subject: [Git-Hub, Active Directory Synch With Ldap] Your Query Description