GitHub Administration
Pre Requisite Software Download/ Registration :
❖ Register @ https://github.com/
❖ Install git bash @ https://git-scm.com/downloads
Git Commands
When you install Git-bash, the first thing you should be doing is setting up your user details as follows only one time.
git config –global user.name “Anselem Chattme”
git config –global user.email “[email protected]”
git config –list
git config –global –list
Task 1: Create the git local repository in local machine (Laptop/Desktop), add one file (DBConnect.java) and update that file, create the github remote repository (https://github.com) and move the local code to github repository. Go to the directory where you want to create the git repository.
cd ~/Desktop
mkdir git-code
cd git-code
git init : Create a local Git empty repository.
Initialized empty Git repository in /Users/anselemchattme/git/git-code/.git/
git status : Gives the status of your untracked files.
touch DBConnect.java
git status
vim DBConnect.java
git add DBConnect.java: Add the files(here DBConnect.java) into your staging area. #git status
On branch master Initial commit
Changes to be committed:
(use “git rm –cached …” to unstage) new file: DBConnect.java
git status
On branch master
nothing to commit, working tree clean
➢ Open the file (DbConnect.java) and update with some text.
vim DBConnect.java
git commit -a -m “Updated DBConnect.java file” : If we use –a along with commit command, no need to execute git add command.
[master 7f795a7] Updated DbConnect.java file 1 file changed, 1 insertion(+)
➢ Create the repository in github as follows. Login into github (http://github.com)
On right side top corner click on “+” symbol and click on “New repository” and give the Repository name and click on Create repository.
git remote add origin Remote Repo URL : Adding the URL for the remote repository where your local repository code will be pushed.
git remote –v :
git remote show origin : It will give the information on a particular remote (here origin is the remote name)
git remote remove origin : It will remove the remote origins.
git push origin master : Push the changes in your local repository to GitHub remote repository. (Here push is the git command , origin is the remote name and master is the branch name)
git branch : It gives the branch names in current repository.
git branch bugfix : It will create the bugfix branch in local git repository.
git branch -v: It will display all the branches in your repo, and also tell you what branch you’re currently in.
bugfix 87226db initial commit
- master 87226db initial commit
Note: Here * indicate currently in use branch.
git checkout bugfix : Switch to bugfix branch. Switched to branch ‘bugfix’
Update the land.txt like change 2 – bugfix branch
git add . : Add one or more files to staging
git commit -m “bugfix commit”
git checkout master : Switch to master branch. Switched to branch ‘master’
Updat the Bhaskar.txt like change 3 – master branch
git add .
git commit -m “master commit”
git checkout bugfix : Switch to bugfix branch. Switched to branch ‘bugfix’
GitHub, Inc. is a provider of the Internet hosting for software development and version control using Git. It offers the distributed version control and source code management functionality of Git, plus its own features. At a high level, GitHub is a website and cloud-based service that helps developers store and manage their code, as well as track and control changes to their code. To understand exactly what GitHub is, you need to know two connected principles, Version control and Git
What Is Version Control?
Version control helps developers track and manage changes to a software project’s code. As a software project grows, version control becomes essential. Take WordPress. At this point, WordPress is a pretty big project. If a core developer wanted to work on one specific part of the WordPress codebase, it wouldn’t be safe or efficient to have them directly edit the “official” source code. Instead, version control lets developers safely work through branching and merging.
With branching, a developer duplicates part of the source code (called the repository). The developer can then safely make changes to that part of the code without affecting the rest of the project. Then, once the developer gets his or her part of the code working properly, he or she can merge that code back into the main source code to make it official. All of these changes are then tracked and can be reverted if need be. While Git is a specific open-source version control system created by Linus Torvalds in 2005. Specifically, Git is a distributed version control system, which means that the entire codebase and history is available on every developer’s computer, which allows for easy branching and merging. Where I currently work we maintain minimum of 3 Stages in github which are DEVELOPMENT, STAGING AND MASTER/MAIN.
File Locations
For different states, the locations of your file will be different. We are going to discuss the complete workflow based on the state and locations of the file.
1. Working Directory
When you create any folder in your system it resides in the working directory or local folder or in your workspace. Basically working directory is the local folder for your project files. Now you might have understood that modified files reside in the working directory. Don’t be confused between the working directory and the .git directory. The working directory is created by the user and . git directory is created by Git.
2. Staging Area
Your files in the staged state reside in the staging area. Basically, the staging area is the “index” in Git parlance located in the .git directory. It stores the information about the files which are queue to be committed.
3. Git Directory
- This directory is the heart of Git where all the magic happens. Files in the committed state reside in this directory.
- The .git directory is created by Git, and it stores the files that are committed or instructed by the user to monitor. The .git folder stores the object databases and metadata of the files.
- git clone command followed by the URL creates a local copy of the repository in your workspace.
- add command add the files from workspace to the index or the staging area. The file is staged, and it is marked to be committed but not yet committed.
- When you execute commit commands all the files that are staged, their changes will be committed to the local repository.
Now, take a look at the picture given below to understand the complete workflow
This past week I completed my first group project at Flatiron School. In the project I used my knowledge of programming with Ruby to create a CLI application which helps users discover new breweries across the United States.
One of the largest hurdles throughout the group project was navigating Git and GitHub. In this post, I hope to help explain the workflow we utilized as well as share some commonly used commands at each stage in the process.
Git & GitHub
Git is a version control system that will help you keep track of the changes and history of your project throughout its lifestyle. I worked through two main components of version control throughout my project:
- Branching – allows you to duplicate the source code for yourself. You will then work on your own branch so your edits do not immediately affect the original source code.
- Merging – the process of joining your branch with the original source code after complete testing.
GitHub is the service that will host your Git repositories. Think of GitHub like the cloud server that hosts your source code. The repository for your project consists of all branches, commit, merge history, any licensing or readme files, rake/gem files, etc.
The partnership between Git and GitHub grant teams an invaluable asset – any and every modification to code is tracked through the two tools. Therefore, in the case of a mistake the code can efficiently and quickly be rolled back to its previous state prior to the error.
Workflow & Commonly Used Commands
Let’s review a simple project workflow and the CLI commands that help us move from one step to the next. Below is a diagram of a workflow including Git & Github. This diagram above most closely represents the flow of my group
This past week I completed my first group project at my workplace Dominion Systems. In the project I used my knowledge of programming with Script to create a CLI application which helps users discover new breweries across the Dominion Systems. One of the largest hurdles throughout the group project was navigating Git and GitHub. In this post, I hope to help explain the workflow we utilized as well as share some commonly used commands at each stage in the process.
Git & GitHub
Git is a version control system that will help you keep track of the changes and history of your project throughout its lifestyle. I worked through two main components of version control throughout my project:
- Branching – allows you to duplicate the source code for yourself. You will then work on your own branch so your edits do not immediately affect the original source code.
- Merging – the process of joining your branch with the original source code after complete testing.
GitHub is the service that will host your Git repositories. Think of GitHub like the cloud server that hosts your source code. The repository for your project consists of all branches, commit, merge history, any licensing or readme files, rake/gem files, etc.
The partnership between Git and GitHub grant teams an invaluable asset – any and every modification to code is tracked through the two tools. Therefore, in the case of a mistake the code can efficiently and quickly be rolled back to its previous state prior to the error.
Workflow & Commonly Used Commands
Let’s review a simple project workflow and the CLI commands that help us move from one step to the next. Below is a diagram of a workflow including Git & Github. This diagram most closely represents the flow of my group.
git clone
The very first step (not included on diagram) is to clone the repository to your local machine. Be sure to clone the project in a working directory that makes sense so you can easily remember where your local project lives.
git pull origin master
Next, pull down from the remote repository (reminder, this lives on GitHub) to make sure you have up to date information. Believe it or not, changes could have been made by a team member in the time it took you to clone down the repository to your computer.
git checkout -b new_branch_name
Create your own branch! If you’re working in a group project like I was, you will probably want to create a new branch for the feature you are working on. Make sure you are titling your branch according to the standards of your workplace expectations. You now have your own little place to experiment with code without immediately affecting changes on the master branch. Note: you might not need to create a new branch if you are intentionally editing an existing branch. In that case, be sure you are on the correct branch and not the master prior to making any changes. Always check with your teammates before creating/editing branches.
git add file_name
After your code has been tested and is complete, add your changes to the staging area. This means that your files are tracked by Git, changes are complete, and code is prepped, and ready to be added back to the repository.
git status
Run git status to confirm that your files have been added to the staging area. If the name of the file is listed in green – you’re good to go! If not, try adding again.
git commit -m “valuable_but_short_message_here”
Commit your changes back to the repository. Add a brief, but detailed comment about the changes that were made, code that was written, or bug that was fixed. Make it easy for your team members and future team members to understand what the alterations were.
git push branch_name
Next up – push your changes to the repository! You have now transferred your code up to GitHub. The code you’ve pushed up lives in the current branch you’ve worked on. We learned (the hard way) how important it is work on your branch and to push to your own branch. If you accidentally push up to the master you run the risk of overwriting code the master branch which lives within GitHub.
Chattme.com can help you find the date or relationship that fits you best. Search free through all of our online personals. Literally, hundreds of thousands of single men and single women right in your area have posted personal ads on our platform.
Finally, you’ll need to create a pull request through GitHub. This may vary depending on the nature of the project. Submitting a pull request will notify the owner of the repository that you are ready to merge your code with the master branch. It is up to the owner to review your code prior to finalizing the merge. In our particular situation we had team members look at the code together as we completed the pull request. Because we were still relatively new to the GitHub process, we wanted to be sure that no code was accidentally overwritten when a branch was merged with the master.
git pull origin master
This command was mentioned above as the first thing you should do after cloning to your machine. Again, you’ll need to complete this once the master has been revised. This command gets a honorable mention for playing a critical role in keeping your working version up to date. After the master branch in a repository has been updated from a pull request, be sure to pull down from the repository into your local branches. This will ensure that you are working on the most up to date files moving forward.
Conclusion
I hope that this post helps to explain some of the fundamentals of using both Git and GitHub. Writing this blog was a valuable exercise to me, as I was able to reflect on the processes that challenged my team and learn more about them through further research. Note that there are many common commands that this post didn’t cover and I encourage you to look those up as needed. I’d love to hear feedback on this post -comments are welcome! Happy coding!
Chattme.com Community Can now learn about Devops Engineer
Git Best Practices
Use branching strategy and pull requests
Commit once you finish the task. Avoid merge commits.
Don’t Commit Half-Done Work Test your code before commit.
Write Good Commit Messages before you are committing Try to use git commands rather than GUI tools.
Who are on those chattme.com? Your neighbors, coworkers and more. Chattme.com members form a diverse, global community of singles who share common goals to meet other singles, find dates, meet family member, form romantic relationships and meet life partners. Young and old alike, gay and straight, from everywhere around the world, singles come to chattme.com to flirt, meet, date, have fun, learn, fall in love and to form meaningful, loving relationships. Our life together has been nothing short of spectacular and so fulfilling. All of this joy and happiness is due to a chance meeting on chattme.com