22 August 2023

How to Run Your Own Git Server

https://www.linuxfoundation.org/blog/blog/classic-sysadmin-how-to-run-your-own-git-server


This is a classic article written by Swapnil Bhartiya from the Linux.com archives. For more great SysAdmin tips and techniques check out our free intro to Linux course.

Git is a versioning system developed by Linus Torvalds, that is used by millions of users around the globe. Companies like GitHub offer code hosting services based on Git. According to reports, GitHub, a code hosting site, is the world’s largest code hosting service. The company claims that there are 9.2M people collaborating right now across 21.8M repositories on GitHub. Big companies are now moving to GitHub. Even Google, the search engine giant, is shutting it’s own Google Code and moving to GitHub.

Run your own Git server

GitHub is a great service, however there are some limitations and restrictions, especially if you are an individual or a small player. One of the limitations of GitHub is that the free service doesn’t allow private hosting of the code. You have to pay a monthly fee of $7 to host 5 private repositories, and the expenses go up with more repos.

In cases like these or when you want more control, the best path is to run Git on your own server. Not only do you save costs, you also have more control over your server. In most cases a majority of advanced Linux users already have their own servers and pushing Git on those servers is like ‘free as in beer’.

In this tutorial we are going to talk about two methods of managing your code on your own server. One is running a bare, basic Git server and and the second one is via a GUI tool called GitLab. For this tutorial I used a fully patched Ubuntu 14.04 LTS server running on a VPS.

Install Git on your server

In this tutorial we are considering a use-case where we have a remote server and a local server and we will work between these machines. For the sake of simplicity we will call them remote-server and local-server.

First, install Git on both machines. You can install Git from the packages already available via the repos or your distros, or you can do it manually. In this article we will use the simpler method:

sudo apt-get install git-core

Then add a user for Git.

sudo useradd git
passwd git

In order to ease access to the server let’s set-up a password-less ssh login. First create ssh keys on your local machine:

ssh-keygen -t rsa

It will ask you to provide the location for storing the key, just hit Enter to use the default location. The second question will be to provide it with a pass phrase which will be needed to access the remote server. It generates two keys – a public key and a private key. Note down the location of the public key which you will need in the next step.

Now you have to copy these keys to the server so that the two machines can talk to each other. Run the following command on your local machine:

cat ~/.ssh/id_rsa.pub | ssh git@remote-server "mkdir -p ~/.ssh && cat >>  ~/.ssh/authorized_keys"

Now ssh into the server and create a project directory for Git. You can use the desired path for the repo.

git@server:~ $ mkdir -p /home/swapnil/project-1.git

Then change to this directory:

cd /home/swapnil/project-1.git

Then create an empty repo:

git init --bare
Initialized empty Git repository in /home/swapnil/project-1.git

We now need to create a Git repo on the local machine.

mkdir -p /home/swapnil/git/project

And change to this directory:

cd /home/swapnil/git/project

Now create the files that you need for the project in this directory. Stay in this directory and initiate git:

git init 
Initialized empty Git repository in /home/swapnil/git/project

Now add files to the repo:

git add .

Now every time you add a file or make changes you have to run the add command above. You also need to write a commit message with every change in a file. The commit message basically tells what changes were made.

git commit -m "message" -a
[master (root-commit) 57331ee] message
 2 files changed, 2 insertions(+)
 create mode 100644 GoT.txt
 create mode 100644 writing.txt

In this case I had a file called GoT (Game of Thrones review) and I made some changes, so when I ran the command it specified that changes were made to the file. In the above command ‘-a’ option means commits for all files in the repo. If you made changes to only one you can specify the name of that file instead of using ‘-a’.

An example:

git commit -m "message" GoT.txt
[master e517b10] message
 1 file changed, 1 insertion(+)

Until now we have been working on the local server. Now we have to push these changes to the server so the work is accessible over the Internet and you can collaborate with other team members.

git remote add origin ssh://git@remote-server/repo-<wbr< a="">>path-on-server..git

Now you can push or pull changes between the server and local machine using the ‘push’ or ‘pull’ option:

git push origin master

If there are other team members who want to work with the project they need to clone the repo on the server to their local machine:

git clone git@remote-server:/home/swapnil/project.git

Here /home/swapnil/project.git is the project path on the remote server, exchange the values for your own server.

Then change directory on the local machine (exchange project with the name of project on your server):

cd /project

Now they can edit files, write commit change messages and then push them to the server:

git commit -m 'corrections in GoT.txt story' -a
And then push changes:
git push origin master

I assume this is enough for a new user to get started with Git on their own servers. If you are looking for some GUI tools to manage changes on local machines, you can use GUI tools such as QGit or GitK for Linux.

QGit

Us

15 August 2023

How to contribute to a software development on Git?

e.g.

1. Log in to GitHub, and on this project's page, click "Fork" to your own repository.
2. Clone your repository to your local machine: 

$ git clone https://github.com/xxx/Ansible-VIM-IDE.git

3. Add the original repository as the upstream branch on the master branch: 

$ git remote add upstream https://github.com/Hello-Linux/Ansible-VIM-IDE.git

4. Create a new development branch locally: 

$ git checkout -b dev

5. Make code changes and commit on the development branch: 

$ git add .

$ git commit -am 'xx change description'

6. Switch to the master branch and synchronize with the original repository: 

$ git checkout master

$ git pull upstream master

7. Switch to the dev branch, merge the local master branch (which is now synced with the original repository), resolving any conflicts if needed: 

$ git checkout dev

$ git merge master

8. Push the local dev branch to your remote dev repository: 

$ git push origin dev

9. On your GitHub repository page, click "Compare & pull request" to send a pull request to the original repository.

10. Wait for the original author's response (accept/reject).

12 August 2023

Free Code Camp | the best place for you to learn software development by your self

https://www.freecodecamp.org/

10 Python Project Ideas for Beginners in 2023

https://www.analyticsinsight.net/10-python-project-ideas-for-beginners-in-2023/

How to install NERDTree for vim? | How to always display a file explorer at the left side in vim?

https://github.com/preservim/nerdtree#readme

How to install NERDTree?

Pathogen Pathogen is more of a runtime path manager than a plugin manager. You must clone the plugins' repositories yourself to a specific location, and Pathogen makes sure they are available in Vim.
  1. In the terminal,
    git clone https://github.com/preservim/nerdtree.git ~/.vim/bundle/nerdtree
  2. In your vimrc,
    call pathogen#infect()
    syntax on
    filetype plugin indent on
  3. Restart Vim, and run :helptags ~/.vim/bundle/nerdtree/doc/ or :Helptags.

 How to display file explorer in vim?

 :NERDTree

06 August 2023

My .vimrc

" set linewidth      
set textwidth=78     

set encoding=utf-8   
set fileencoding=utf-8

" enable syntax highlighting
syntax enable        

" show line numbers  
set number           

" set tabs to have 4 spaces
set ts=4             

" indent when moving to the next line while writing code
set autoindent       

" expand tabs into spaces
set expandtab        
                     
" when using the >> or << commands, shift lines by 4 spaces
set shiftwidth=4

" show a visual line under the cursor's current line
" set cursorline        
                        
" show the matching part of the pair for [] {} and ()
set showmatch           

set guifont=Consolas:h11

" avoid word breaking at end of each screen line
set linebreak           

" enable all Python syntax highlighting features
let python_highlight_all = 1

set splitbelow          
set splitright          

nmap <C-h> <C-w>h       
nmap <C-j> <C-w>j       
nmap <C-k> <C-w>k       
nmap <C-l> <C-w>l       
                        
" vim-pathogen          
execute pathogen#infect()
syntax on               
filetype plugin indent on

" Ctrl-P                
set runtimepath^=~/.vim/bundle/ctrlp.vim
"                                                                 *'g:ctrlp_map'*
" Use this option to change the mapping to invoke CtrlP in |Normal| mode:
let g:ctrlp_map = '<c-p>'
"                                                                 *'g:ctrlp_cmd'*
" Set the default opening command to use when pressing the above mapping:
let g:ctrlp_cmd = 'CtrlP'
"                                                  *'g:ctrlp_working_path_mode'*
" When starting up, CtrlP sets its local working directory according to this
" variable: >        
let g:ctrlp_working_path_mode = 'ra'

set colorcolumn=5,9,13,17,21

" NERDTree settings  
"                    
" Start NERDTree. If a file is specified, move the cursor to its window.
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * NERDTree | if argc() > 0 || exists("s:std_in") | wincmd p | endif

" Open the existing NERDTree on each new tab.
autocmd BufWinEnter * if getcmdwintype() == '' | silent NERDTreeMirror | endif

let NERDTreeWinSize = 20

" toggle between line wrapping and unwrapping
map <C-a> :set wrap!<CR>

" set colorcolumn color
:hi ColorColumn ctermbg=lightgrey guibg=lightgrey