Showing posts with label git. Show all posts
Showing posts with label git. Show all posts

Wednesday, November 29, 2017

How push or sync commits to a different branch

Let’s say we have created a branch yesterday and committed some changes to master branch.
If we want to make both the branches even.
  1. Option 1 -> is to delete and recreate the branch again from master.
  2. Option 2 -> checkout to master branch and run below command.
    git push origin master:<new_branch>
All the commits are identified by a unique ID.So we don’t need to mention the parent branch of the commit if we know its ID.So, If we want to add only a specific commit, then run below command from the target branch checked out.
git checkout -b new_branch origin/new_branch -> If branch never checked out locally.
git checkout new_branch -> If already checked out locally.
git cherry-pick <commit-ID>
Reference: https://www.devroom.io/2010/06/10/cherry-picking-specific-commits-from-another-branch/

Git Remote end Hung Up error

When you get a remote hung up error while trying to push the local repository to GitHub server, 2 cases arises.
1. Your local network issues.
2. GitHub upload size limit.
For the first case, to have a resume option, you can use the tool like Sourcetree.
For the second case, even though the individual file size limit is maintained, there is a size limit for pushing the repository but not one the complete code size.
The limit is 2 GB now.
If your repository is of more size.Then we can push in partitions.
This option is available with the help of below command, where the number of commits to be published are limited only till the commit code we specify.
git push <repo_name> <commit ID>:refs/heads/<branch_name>
Let’s say we have 1000 commits and we specify the 50th commit, then the commits from 1 to 50 will be pushed and later are skipped, if we specify the 150th commit later, then as already 50 commits are pushed, the commit range 51 to 150 will be pushed.

How to exclude all the files except files starting with a name in the Git or GitHub

In the GIT project, I have many .sql files in it related to different databases.
Is there anyway I can exclude all the files except the files starting with “Hive_” in my Git Project.
Is there anyway to do so in .gitignore file.
Through .gitignore I can exclude the files list.
But the current requirement is reverse here, I want to exclude everything except files starting with specific characters.
To do that.
Create a .gitignore file in the root folder of the repository.
The .gitignore contents:
————————————–
# excluded all files
*.*
# except all files prefixed with Hive_
!Hive_*

How to exclude all files except some pattern in git

In the GIT project, I have many .sql files in it related to different databases.
Is there anyway I can exclude all the files except the files starting with “Hive_” in my Git Project.
Is there anyway to do so in .gitignore file.?
Through .gitignore I can exclude the files list.
But the current requirement is reverse here, I want to exclude everything except files starting with specific characters.
The answer is below.
You can use below pattern in your gitignore file.
# Ignore all
*
# but except below
! Hive_*

Jenkins issue with fetching GitHub Data

To operate GitHub based source code repositories in Jenkins.All you need to install the Git Plugin.
And below configurations are required.
1. Goto Manage Jenkins → Global Tool configuration. → Scroll to Git section and keep the Name as is and “Path to Git Location as just git.exe“. As we are going to keep the git.exe folder to the environment variable path.
2. While installing Git on your machine, don’t forget to uncheck the feature “Git credential manager”.
3. Once it is done create a free style project and add the github url to the source code management section in job configuration page by selecting the radio button git there.
jenkisn_1
Give values for below options.
Jenkins_2
When you try to build the project, you may get issues like timeout while fetching the github repo.
Like in the below post: Stackoverflow
The issue is because the git.exe is trying to access git credential manager for the credential support.All you need to do is to uninstall and reinstall again by uncheking the git credential manager sub feature.