Git Setup | First time with git and github | GitHub Setup | Git Commands | Moving Changes from local to remote
STEP 1: CREATE A FOLDER IN COMPUTER(LOCAL REPO)
Open terminal
Goto desktop (cd Desktop)
mkdir Story(Creating a folder name Story )
Cd Story
Create Chapter1.txt file (inside story Folder)
Write QUESTIONS on Chapter1.txt and save it
Come back to terminal
STEP 2: Add Git FOLDER and move Changes(LOCAL REPO) to STAGING AREA
Write git init (Initialise empty git repo)
(Make sure in correct folder which u want to push to remote)
As soon as u enter git init .git file is generated
If u write ls it won’t show u hv to write ls-a to see hidden files
.git file — tracks all your changes, to commit your changes and to perform version control
So currently we are under working directory that is story directory
To Track the files I need to add the files in staging area
Enter git status
Git status shows you that there are untracked files which will be shown in red and this is something inside your working directory but its not yet in the staging area
So in order to add it to staging area and to start tracking changes in it, then we have to use command “git add” filename
Enter git status again, you can see that file has been moved to staging area(green color)
Now files are in staging area ready to be committed
Git commit -m “commit Message ”
Enter git log ( to see what commit u made)
Git diff filename (gives u the difference in changes)
Git checkout “filename” (this command reverts your file to previous change)
STEP 3: Moving Changes to Remote Area
Go to GitHub.com {
- login to GitHub
- create new repository( by clicking + Sign located at top Rightmost corner next to your profile icon)
- Give repository Name
- select private option
- click create repository button
- click check box stating Initialize this repository with a README
- copy the path (something like https://github.com/p77/Story.git)
To push changes to remote repo we need to copy the address of our Github repo and
We are going to use below two lines of code
git remote add origin https://github.com/p77/Story.git
git push -u origin master
- Make sure you are in your local repo folder
- enter git log ( to see previous commits)
- now we need to push these commits to remote(GitHub)
- now add command
git remote add origin https://github.com/p77/Story.git
Now remote is created, now we can push our local repository onto our remote repository which is Called origin
Now enter git push -u origin master
Here master is the main branch of all your commits
STEP 4: Git Useful Commands
- Create .gitignore file
touch .gitignore (create gitignore file)
open .gitignore
In .gitignore file u can add your filename and these will be ignored for GitHub
• Create a New branch
git branch branchName
• To check in which branch you are present
git branch
• To switch to branch
git checkout particularBranchName
• To Push changes to remote
git push -u origin feature branch