how to properly upload your project on github

New to git? Follow the steps below to get comfortable making changes to the code base, opening up a pull asking (PR), and merging code into the master branch. Whatever important git and GitHub terms are in assuming with links to the official git reference materials.

Step 0: Install git and create a GitHub business relationship

The first two things you'll want to do are install git and create a free GitHub account.

Follow the instructions hither to install git (if it'south not already installed). Note that for this tutorial nosotros volition exist using git on the command line only. While there are some great git GUIs (graphical user interfaces), I think it's easier to acquire git using git-specific commands first and and then to try out a git GUI once y'all're more than comfortable with the command. A notation: 95% of other online git resources and discussions will too be for the command-line interface.

In one case you've done that, create a GitHub account here.

Git and GitHub

A quick aside: git and GitHub are non the aforementioned thing. Git is an open up-source, version control tool created in 2005 past developers working on the Linux operating system; GitHub is a company founded in 2008 that makes tools which integrate with git. Yous practise not need GitHub to use git, just y'all cannot use GitHub without using git. There are many other alternatives to GitHub, such as GitLab, BitBucket, and "host-your-ain" solutions such as gogs and gittea. All of these are referred to in git-speak as "remotes", and all are completely optional. You lot do not demand to utilize a remote to employ git, just it will make sharing your code with others easier.

Step 1: Create a local git repository

When creating a new projection on your local machine using git, yous'll first create a new repository (or often, 'repo', for brusque).

To use git we'll be using the final. If you don't take much feel with the terminal and basic commands, bank check out this tutorial (If yous don't desire/ need a brusk history lesson, skip to step three.)

To brainstorm, open up up a concluding and movement to where you want to place the project on your local automobile using the cd (modify directory) command. For example, if y'all have a 'projects' folder on your desktop, y'all'd do something like:

To initialize a git repository in the root of the folder, run the git init command:

Step ii: Add a new file to the repo

Become ahead and add a new file to the project, using whatever text editor you similar or running a touch control. `touch newfile.txt` but creates and saves a blank file named newfile.txt.

Once you lot've added or modified files in a folder containing a git repo, git volition find that  the file exists inside the repo. But, git won't track the file unless yous explicitly tell it to. Git only saves/manages changes to files that it tracks, and so we'll need to send a command to confirm that yes, we want git to track our new file.

After creating the new file, you can use the git status command to see which files git knows be.

What this basically says is, "Hey, we noticed you created a new file called mnelson.txt, but unless yous utilize the 'git add' control we aren't going to do anything with it."

An interlude: The staging environment, the commit, and you

1 of the near confusing parts when you're first learning git is the concept of the staging surround and how it relates to a commit.

A commit is a tape of what changes you lot have made since the last fourth dimension you fabricated a commit. Essentially, yous make changes to your repo (for example, adding a file or modifying 1) and then tell git to put those changes into a commit.

Commits make up the essence of your project and allow you to bound to the state of a project at any other commit.

So, how practise you tell git which files to put into a commit? This is where the staging environment or alphabetize come up in. As seen in Footstep 2, when you make changes to your repo, git notices that a file has changed but won't do anything with it (like calculation information technology in a commit).

To add together a file to a commit, you get-go demand to add together it to the staging environment. To do this, you can utilize the git add <filename> command (see Step 3 below).

Once you've used the git add together command to add all the files yous desire to the staging environment, you can then tell git to package them into a commit using the git commit command.

Note: The staging environment, as well chosen 'staging', is the new preferred term for this, merely you tin can as well run into information technology referred to as the 'alphabetize'.

Step three: Add a file to the staging environment

Add together a file to the staging environment using the git add together control.

If you rerun the git status command, y'all'll come across that git has added the file to the staging surround (notice the "Changes to be committed" line).

To reiterate, the file has notyet been added to a commit, simply it's about to exist.

Step 4: Create a commit

It's fourth dimension to create your first commit!

Run the command git commit -m "Your bulletin about the commit"

The message at the terminate of the commit should be something related to what the commit contains - perhaps it'due south a new feature, perchance it'south a problems set up, maybe it'due south just fixing a typo. Don't put a message similar "asdfadsf" or "foobar". That makes the other people who come across your commit sad. Very, very, sad. Commits live forever in a repository (technically you lot can delete them if you lot really, really need to simply it's messy), and then if you leave a clear caption of your changes it tin can be extremely helpful for futurity programmers (perhaps future you!) who are trying to effigy out why some change was fabricated years later.

Footstep 5: Create a new co-operative

Now that you've fabricated a new commit, let'due south effort something a little more advanced.

Say yous want to make a new feature but are worried almost making changes to the master project while developing the feature. This is where git branches come in.

Branches allow you lot to move dorsum and forth between 'states' of a projection. Official git docs describe branches this way: 'A co-operative in Git is just a lightweight movable pointer to one of these commits.' For instance, if you lot want to add a new page to your website you can create a new branch merely for that folio without affecting the main part of the projection. One time you're washed with the page, you can merge your changes from your branch into the primary branch. When you create a new branch, Git keeps track of which commit your co-operative 'branched' off of, and so it knows the history behind all the files.

Let's say you are on the primary co-operative and want to create a new branch to develop your spider web page. Here'south what y'all'll do: Run git checkout -b <my co-operative name>. This command volition automatically create a new co-operative and and then 'check you out' on it, meaning git will motion you lot to that co-operative, off of the principal branch.

After running the to a higher place control, you can use the git co-operative command to ostend that your branch was created:

The branch proper name with the asterisk next to information technology indicates which branch you're on at that given time.

A note on branch names

By default, every git repository's first branch is named `master` (and is typically used as the primary branch in the project). As part of the tech industry's general anti-racism piece of work, some groups have begun to use alternating names for the default branch (we are using "primary" in this tutorial, for example). In other documentation and discussions, you lot may meet "master", or other terms, used to refer to the master branch. Regardless of the name, merely go along in mind that nearly every repository has a primary branch that can exist thought of as the official version of the repository. If information technology's a website, then the primary co-operative is the version that users run across. If it's an awarding, and so the chief branch is the version that users download. This isn't technically necessary (git doesn't treat whatever branches differently from other branches), just information technology'southward how git is traditionally used in a project.

If yous are curious about the conclusion to use different default branch names, GitHub has an explanation of their change here: https://github.com/github/renaming

Now, if you switch back to the principal co-operative and brand some more commits, your new branch won't see any of those changes until you merge those changes onto your new branch.

Step 6: Create a new repository on GitHub

If you only desire to keep track of your code locally, you don't need to use GitHub. Merely if you desire to work with a squad, you can use GitHub to collaboratively modify the project's code.

To create a new repo on GitHub, log in and get to the GitHub home page. You lot can find the "New repository" pick nether the "+" sign side by side to your contour pic, in the summit correct corner of the navbar:

Git_1

After clicking the push button, GitHub will ask you to name your repo and provide a brief clarification:

Git_2

When you're done filling out the data, printing the 'Create repository' button to make your new repo.

GitHub will enquire if you want to create a new repo from scratch or if yous want to add together a repo you accept created locally. In this case, since we've already created a new repo locally, we want to button that onto GitHub so follow the '....or push an existing repository from the control line' section:

(You'll desire to modify the URL in the first command line to what GitHub lists in this section since your GitHub username and repo proper noun are different.)

Stride 7: Push a branch to GitHub

Now we'll push button the commit in your branch to your new GitHub repo. This allows other people to see the changes you've made. If they're approved past the repository's owner, the changes can and then be merged into the chief branch.

To push changes onto a new branch on GitHub, you lot'll want to run git push origin yourbranchname. GitHub will automatically create the branch for you on the remote repository:

Yous might be wondering what that "origin" word means in the command in a higher place. What happens is that when y'all clone a remote repository to your local machine, git creates an alias for you. In nearly all cases this alias is chosen "origin." It's essentially shorthand for the remote repository's URL. So, to push your changes to the remote repository, you could've used either the command: git push git@github.com:git/git.git yourbranchname or git push origin yourbranchname

(If this is your get-go time using GitHub locally, information technology might prompt you to log in with your GitHub username and password.)

If you refresh the GitHub page, you'll run across note maxim a co-operative with your proper noun has just been pushed into the repository. You tin can also click the 'branches' link to encounter your branch listed there.

Git_3

Now click the green button in the screenshot higher up. We're going to make a pull request!

Pace 8: Create a pull asking (PR)

A pull request (or PR) is a way to alarm a repo's owners that y'all desire to make some changes to their code. Information technology allows them to review the code and brand sure it looks good before putting your changes on the primary branch.

This is what the PR page looks like before you lot've submitted it:

Git_4

And this is what it looks like in one case yous've submitted the PR asking:

Git_5

You lot might see a big green push at the bottom that says 'Merge pull request'. Clicking this means you'll merge your changes into the chief branch..

Sometimes y'all'll be a co-owner or the sole owner of a repo, in which case you may non demand to create a PR to merge your changes. However, it's still a practiced idea to make 1 so you can keep a more complete history of your updates and to brand sure you ever create a new co-operative when making changes.

Pace 9: Merge a PR

Become alee and click the light-green 'Merge pull request' button. This volition merge your changes into the principal branch.

Git_6

When you're washed, I recommend deleting your branch (too many branches can become messy), and so hit that grey 'Delete branch' button as well.

You tin double check that your commits were merged by clicking on the 'Commits' link on the first page of your new repo.

Git_7

This will show you a list of all the commits in that co-operative. You can encounter the one I just merged right up top (Merge pull request #1).

Git_8

Yous can also see the hash code of the commit on the right paw side. A hash code is a unique identifier for that specific commit. It's useful for referring to specific commits and when undoing changes (use the git revert <hash code number> command to backtrack).

Step 10: Get changes on GitHub back to your computer

Right now, the repo on GitHub looks a piffling dissimilar than what you have on your local automobile. For example, the commit yous made in your branch and merged into the primary branch doesn't exist in the main branch on your local machine.

In order to get the most recent changes that you or others have merged on GitHub, use the git pull origin master command (when working on the main branch). In near cases, this can be shortened to "git pull".

This shows you all the files that accept changed and how they've changed.

Now we can utilise the git log command again to see all new commits.

(You may need to switch branches back to the primary branch. You tin do that using the git checkout master command.)

Step 11: Bask in your git celebrity

You've successfully made a PR and merged your code to the primary branch. Congratulations! If you'd like to dive deeper, check out these more advanced tutorials and resources:

  • https://training.github.com/
    Github's official git crook sheets! Handy for remembering the everyday commands yous'll use.
  • https://learngitbranching.js.org/
    Confused or intrigued by git's branch system? That just means you're human! It's one of the deepest parts of git, merely besides arguably the nigh powerful. Understanding the branch model gives you git superpowers, and this tutorial gives you lot a way to larn git branches in a visual, intuitive way.
  • https://git-school.github.io/visualizing-git
    Another tool for exploring git visually. This one is more of an open-ended sandbox than learngitbranching.js.org
  • https://github.com/jlord/git-it-electron
    A desktop awarding that helps you larn git through challenges you have to solve. It has a series of levels, each requiring you to apply git commands to arrive at a correct respond.
  • https://github.com/Gazler/githug
    If you liked git-it, Githug is another puzzle-based tutorial designed to give you a practical way of learning git.

I also recommend finding some time to work with your team on simulating a smaller group project like we did hither. Have your squad make a new folder with your team name, and add some files with text to it. Then, effort pushing those changes to this remote repo. That fashion, your team can showtime making changes to files they didn't originally create and practice using the PR characteristic. And, use the git blame and git history tools on GitHub to go familiar with tracking which changes have been made in a file and who fabricated those changes.

The more than yous use git, the more comfy y'all'll... git with it. (I couldn't resist.)

*This post was originally published in October 2022 past Meghan Nelson, and then a senior software engineer at HubSpot. It has since been updated by the HubSpot Product Squad.

Interested in working for a product team that values autonomy and transparency? Cheque out our open positions and apply.

reavesextouralke.blogspot.com

Source: https://product.hubspot.com/blog/git-and-github-tutorial-for-beginners

0 Response to "how to properly upload your project on github"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel