10

How to Upload a Project on Git

 2 years ago
source link: https://www.laravelcode.com/post/how-to-upload-a-project-on-git
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How to Upload a Project on Git

  483 views

  9 months ago

Git

Suppose you are working in a big project and after some changes you want to revert some changes and want to work with new codes. Also when team is working in one project, then how to share their work? Here comes the Git!

Git is the open source distributed version control system developed by Linux Torvalds as a part of Linux Kernal development. Git makes all community developers to share your project and work colloborately.

In this article, we will not go deep about what is git, or how git works. Rather than we will upload project on GitHub using command line tool, one of the most popular Git repository hosting service. There are also many other popular Git service providers are available, like Bitbucket, GitLab, which provides free private repository. You can go any of them, all commands will be same for all Git client. So let's start.

Git installation and setup

First of all, you need to have git installed in your local machine. Run this command in Terminal to check if git is already installed.

git --version

You should get git version in output

git version 2.7.4

Else you need to install git with bellow command:

sudo apt-get install
sudo apt-get install git

After that Git is installed, you need to set your username and email address. All your commits will be shown with this information.

git config --global user.name "jiteshmeniya"
git config --global user.email [email protected]

GitHub account

Now if you don't have GitHub account, create new Github account. For GitHub, go to GitHub and register. All of your uploaded project will be stored in your account. After you have created account, create new GitHub repository.

create-new-github-project-l.png

Upload project to GitHub

Now your git repository is ready to upload project, perform following command to upload project in Git. For that, go to project root directory in Terminal.

cd my-new-project

Initialise with Git repository in project

git init

Stage all files to Git index

git add --all

You can also add selected files to index

git add file1 file2

Commit your changes

git commit -m "Initial upload"

Now add your remote url to local project. If you want to add ssh url, then you need to set ssh key in your local machine. origin is the name of git repository in your local project. You can add as many git repository to your local project as you want.

git remote add origin https://github.com/jiteshmeniya/My-new-project.git

github-https-ssh-git-link.png

and push the code in git repository

git push -u origin master

If you added HTTPS remote url, then you need to enter your GitHub username and password. Now your project is live on GitHub.

Some important Git command.

You can track your changed files in local project.

git status

You can also track changes made in your file.

git diff file.txt

Update your local project from Git repository

git pull origin master

You can clone(download) public git repository

git clone repository-url

Check all Git remote repositories

git remote -v

Get repository url of origin 

git remote get-url origin

Remove origin repository url from project

git remote rm origin

Change repository url

git remote set-url origin new-url

Show your all local branch

git branch

Create a new branch

git branch branch-name

Change working branch

git checkout branch-name

Merge new branch to master

git checkout master
git merge branch-name

Conclusion

This way you can easily upload your local project to new git repository. Please comment bellow if we forget to add basic Git command.

Author : Harsukh Makwana
Harsukh Makwana

Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK