Git and GitHub
Git Install:
Download the git from the following website.
Using Git with Terminal:
If we want to check the git version.
git --version
Configure Git:
git config --global user.name "name"
git config --global user.email "email"
change the user name and email addresses to your own.
Create Git Folder:
First, create a folder.
mkdir project
cd project
mkdir is used to create the folder and cd is used to change the directory.
Initialize Git:
First, we have to initialize Git.
git init
create your project file and save it into a folder.
to check the current working directory. Go back into the terminal and list the file.
ls
then check the status of git.
git status
Files in the Git repo folder can be in two states.
Tracked - This means that files and added to the repo.
Untracked - This means that files and not added to the repo.
To Add the file:
git add filename
if files are added, then the message will show that no commits yet.
Add all files in the repo.
git add --all
to move from staging to commit in repo.
git commit -m "message"
Now check the status of git.
git status
It will show that we have committed to the message.
Git Commit Log:
To view the history of commits.
git log
Git Branch:
We create a new branch.
git branch
To checkout the branch.
git checkout <filename>
now update the commit by adding untracked files.
Merge Branches:
change the branch
git checkout master
Now merge the current branch with the branch you created earlier.
git merge <branch-name>
Now check the git status.
GitHub:
First, create the account on GitHub.
and then
Create Repo on Github:
after creating an account. Go to the plus sign (+) near the account avatar. Click on it and select create repo. Fill in all relevant information and click on create repo button. To push the local repo to GitHub repo first copy the URL and paste the following command into the terminal.
git remote add origin URL
now can push our master branch to the origin URL and set it as the default remote branch.
git push --set-upstream origin master
After a change in the code. Add and commit the changes into the code with a message.
then check the status of git by the following command.
git status
Now push the code to the remote origin.
git push origin
All Git and GitHub Commands:
Git commands:
git init
: Initialize a Git repositorygit clone [repository]
: Clone a remote repositorygit add [file]
: Stage a file for commitgit commit -m [message]
: Commit changes with a messagegit push [remote] [branch]
: Push changes to a remote repositorygit pull [remote] [branch]
: Pull changes from a remote repositorygit status
: Show the status of the current repositorygit log
: Show the commit historygit diff
: Show changes between commitsGitHub commands:
gh repo create [repo_name]
: Create a new repository on GitHubgh repo clone [repo_name]
: Clone a repository from GitHubgh issue create [title] [body]
: Create a new issue on GitHubgh pull-request create [base] [head] [title] [body]
: Create a pull request on GitHubgh release create [tag_name] [title] [body]
: Create a release on GitHub