Tuesday, March 19, 2024

Git steps

  1.  git Init ( Initialize Git repo)
  2. git status (shows untracked files)
  3. git add <filename> ( add files to git staging area) [ git add . to add all the files]
  4. git commit -m"<commit msg>" ( commit the change to git repo)
  5. git log (shows the commit)
                                git add                           git commit
Working Directory ----------> Staging Area ---------------> Local Git Repo

git diff <filename> shows the difference of content of the file.

git checkout <filename> rolls back the file to the last committed version.
git remote add <name> <url>
By convention, name is origin.

                           git push -u <remote name> <branch name>
Local Git Repo ---------------------------------------------------------> Remote Repo

git push -u origin main

To remove files from staging area,

git rm --cached - r .    <rm means remove, r means recursive>

Use .gitignore file to ignore some files.

git clone to clone from remote repo to local repo.

git clone <url>

For creating a new branch, 

git branch <branch-name>

To check available branches,

git branch

To switch branches,

git checkout <branch-name>

To merge changes

git merge <name-of-branch> ( go to main branch and then use merge )


No comments:

Post a Comment