Connecting git to GitHub for Small Projects – InApps Technology is an article under the topic Software Development Many of you are most interested in today !! Today, let’s InApps.net learn Connecting git to GitHub for Small Projects – InApps Technology in today’s post !
Read more about Connecting git to GitHub for Small Projects – InApps Technology at Wikipedia
You can find content about Connecting git to GitHub for Small Projects – InApps Technology from the Wikipedia website
In the last installment on how to use the open source git version control software, we talked about setting up git on a late-model Linux notebook. We went over creating the directory for the files, initializing the git environment to track the files and how to put the files in a repository. All of the work was done on the Linux command line, within a standard terminal window.
In this installment, we’ll look at setting up a GitHub account on the Internet, how you send local content (repositories) up to your account and how to keep everything in sync. Although, I thought we might talk about the tree structure and analyzing commits, I’ll put that off to a later date. Getting the basic machinery working before starting to dig down into the finer points of using git will keep things at the proper level, right now.
We’ll end our discussion with a bit of how you get content out of GitHub and back down to your Linux notebook.
Set up a New GitHub User Account
Git is inherently local. In other words, it will track your files and make snapshots of your work with or without a network connection or centralized storage. When you want to collaborate with others or bring in outside code, connecting to a git service is useful. One such git service is GitHub. Thinking in terms of a single user, GitHub is also a great way archive your work up in the cloud.
The service has a nice web-based interface, including a built-in text editor that you can use from your browser. Others, on the Web can also look at your project through kind of a “read-only” mode. I want to use GitHub to organize and promote my projects.
And in the software development world, the first thing a tech person wants to know is your GitHub address. Right?
Go to the GitHub main page and sign up as a new user.
- Enter your email address on the “Welcome to GitHub – Let’s Begin The Adventure” page.
- Create a password.
- Enter a username you’d like to use for the account.
- Choose yes or no to receive GitHub notifications.
- In order to verify that you are a human user, GitHub will present a run-of-the-mill puzzle to solve. Follow the directions, solve the puzzle, then click the “create account” button. GitHub will send a launch code to the email address you entered earlier.
- Check your email and type the launch code, into the appropriate box in your browser screen.
- Skip the plan type page.
- Press the “continue for free” button. This should get you to your main GitHub screen.
With the account in place, we can now establish a new repository, on GitHub, for our project.
- Click on the repository tab. You’ll notice you are at the github.com/[your username] directory.
- Select the “new” button.
- On the create new repository page, ensure that you are the correct user.
- Add your new repository name. In my case it was “track-h”.
- Select who will be able to see the repository. I chose the “public” option.
- Skip creating the readme, .gitignore, etc. files, for now.
- Press the green “create repository” button.
Choosing to build the readme, etc. files, at the beginning will make it confusing when you try to do your first push of the local repository on your Linux notebook up to your newly created GitHub repository on the network. GitHub will grumble about the synchronization of your files, before you’ve even tried to push any up. You can always add and edit the readme and other files later.
The new repository on GitHub should now be functional.
Before we can send anything from our Linux notebook repository up to GitHub, we have to get an authorization token. Authorization tokens took effect in August 2021. Before then, you could simply use a user name/password combination. Tokenized access is more secure and isn’t too hard to set up or use.
Go to the main GitHub screen, in your browser. The easiest way to do this is to type https://github.com/[your username] into the URL box. Likewise, if you are down in a repository for some reason, click the username directory level at the upper left-hand corner of the screen. In my case, it might be something like drtorq/bio. I’d select the drtorq part because that is my username.
- Open the account drop-down menu at the upper right-hand corner of the screen and select the “settings” button.
- Under the “Account Settings” menu, scroll down and select “Developer Settings”.
- Press the “personal access tokens” button, on the GitHub Apps page, on the left-hand side of the screen.
- Press the “generate new token” button.
- Fill in a descriptive note, to describe what is in the repository.
- Select an expiration period from the menu. 60 days works for me.
- Select the topics you want to administer with the token. Since I don’t know what all the items are yet, I just checked them all.
- Finally, press the “generate token” button.
The token will appear on the screen. You should carefully write it down for future use. You can also save the token as a text string somewhere. I copied mine to my desktop clipboard through Clipman. That way when I get to the spot where we need to use the token, I’ll just paste it into the correct place and hit enter.
Pushing a Repository up to GitHub
Sending files up to the new GitHub repository is straightforward, once you have the initialization and token established correctly.
On the Linux command line, I executed the following.
drtorq-notebook% cd track-h
drtorq-notebook% git remote add origin https://github.com/drtorq/track-h.git
drtorq-notebook% git branch -M main
drtorq-notebook% git push -n origin main
The first line puts me into my track-h repository directory.
Next, the git remote command connects the web address of my newly created GitHub repository to a local (on the Linux notebook) repository reference or pointer, called “origin”.
If you want to change the branch name from the default, the git branch -M command will work. We had changed it when first setting up the account on the Linux notebook, so this one is optional.
Finally, I pushed the last commit of the repository up to GitHub with the git push command.
git push will ask for your user name, which in my case is [email protected] and then the password. Type or paste the token in place of the password. If everything worked right you should see a summary of the transaction, as in the figure below. Take a look at the summary. We’ll get into the specifics at another time. For now, this one just shows a successful push.
If you then go up to the repository on GitHub (in your browser) you can see that the current files there, reflect the changes made down on the local Linux notebook. For example, if I added a new line in text4.txt and then did the commit/push, the text4.txt file (on GitHub) will show the new line, upon clicking on the file in my browser window in the GitHub account.
Pulling down to the Linux Notebook
Getting updates back down to the Linux laptop isn’t very much of a chore, either.
Assuming you are still in the track-h directory, down on the Linux notebook, it’s a simple matter of using the git pull command.
drtorq-notebook% git pull origin
The above figure shows file4.txt on the Linux notebook. I then edited the file on GitHub using their built-in browser-based editor and added a line. The bottom of the editor has a “commit” button that commits the file on the GitHub repository.
The middle part of the screenshot shows the git pull request.
Lastly, you see the file after the git pull confirming that the line was updated in the local file4.txt file.
This is a good stopping point for the second installment of our git learning series.
So far we’ve looked at setting up git on a Linux notebook and covered the basics of connecting our repository up on a git service, such as GitHub. That is a lot to digest and get straight in your head. You may want to peruse a couple of basic video tutorials for git.
Next time, I’ll delve into how I might put some of my real-world content into a repository and start to use git and GitHub to organize a project. It might also be nice to see how to pull down other people’s projects and use them locally on a Linux notebook. git makes tracking, organizing and sharing content pretty easy.
Contact Rob “drtorq” Reilly for consultation, speaking engagements and commissioned projects at [email protected] or 407-718-3274.
InApps Technology is a wholly owned subsidiary of Insight Partners, an investor in the following companies mentioned in this article: Torq.
Let’s create the next big thing together!
Coming together is a beginning. Keeping together is progress. Working together is success.